为什么创建表操作将所有者作为“yugabyte”附加到新表,但连接到的数据库具有不同的所有者?

我在笔记本电脑上的 minikube 中安装了 yugabytedb,并创建了一个所有者为“Rodgers”的数据库。然后我运行 ysqlsh 从终端执行 ysql 命令,其中之一是“CREATE DATABASE ...”。

问题 当我尝试使用外部 Go 应用程序通过向应用程序提供用户为“Rodgers”和设置的密码来连接数据库时,它无法连接。我发现创建的表附加到所有者“yugabyte”,而不是“Rodgers”。但是我连接的数据库和运行 CREATE DATABASE 命令的数据库属于 Rodgers。

这里发生了什么?



慕斯王
浏览 206回答 1
1回答

Helenr

最好使用“ysqlsh”排练所有这些。当一切都在那里工作时,从任何客户端程序(Python、go、...)等连接都可以工作——只要你有正确的驱动程序。PostgresSQL 驱动程序与 YugabyteDB 一起使用。以下主要是“ysqlsh”的命令——包括 SQL 和所谓的元命令(以反斜杠开头的命令)。但有时,您可以从 O/S 提示符执行一些命令。因此,您必须仔细阅读以下内容,然后在每条评论之后按照它所说的去做——主要是在“ysqlsh”中,但在 O/S 提示符下几次。所以你不能简单地运行脚本“熄灯”。从原始 YB 单节点集群(来自“yb-create”的新)开始。$ ysqlsh -h localhost -p 5433 -d yugabyte -U yugabyte现在按照脚本。--  Shows two "Superuser" users: "postgres" and "yugabyte" (nothing else).\du-- Shows two databases: "postgres" and "yugabyte" (nothing else except "system" databases).-- Both "postgres" and "yugabyte" databases are owned by "postgres".\l-- Create a new "ordinary user and connect as that user.create user rodgers login password 'p';alter user rodgers createdb;-- Now connect to database yugabyte as user rodgers\c yugabyte rodgers-- Create a new database and check it's there.create database rog_db owner rodgers;\l --       Name       |  Owner   | Encoding | Collate |    Ctype    |   Access privileges   -- -----------------+----------+----------+---------+-------------+-----------------------   ...--  rog_db          | rodgers  | UTF8     | C       | en_US.UTF-8 |-- ...-- Now connect to the new "rog_db" database. Works fine.\c rog_db rodgers-- Quit "ysqlsh.\q再次连接。工作正常。$ ysqlsh -h localhost -p 5433 -d rog_db -U rodgers现在继续执行脚本。-- Works fine.create table t(k int primary key);-- Inspect it. First "\d", then "\d t".\d--         List of relations--  Schema | Name | Type  |  Owner  -- --------+------+-------+-----------  public | t    | table | rodgers\d t--                  Table "public.t" Column |  Type   | Collation | Nullable | Default -- --------+---------+-----------+----------+-----------  k      | integer |           | not null | -- Indexes:--     "t_pkey" PRIMARY KEY, lsm (k HASH)-- This is OK for playing. But terrible for real work.drop table t;\c rog_db yugabytedrop schema public;\c rog_db rodgerscreate schema rog_schema authorization rodgers;-- For future connect commands.alter user rodgers set search_path = 'rog_schema';-- for here and now.set schema 'rog_schema';create table t(k int primary key);\d--           List of relations--    Schema   | Name | Type  |  Owner  -- ------------+------+-------+-----------  rog_schema | t    | table | rodgers--------------------------------------------------------------------------------我刚刚在我的笔记本电脑(macOS Big Sur)上使用“YB-2.2.0.0-b0”完成了所有这些操作。一切都很好。请在您的 minikube 环境中尝试此操作并报告。此致,Yugabyte Inc. 技术产品经理 Bryn Llewellyn。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go