Database 为什么创建表操作将所有者附加为';尤加比特';到一个新表,但连接到的数据库有不同的所有者吗?

Database 为什么创建表操作将所有者附加为';尤加比特';到一个新表,但连接到的数据库有不同的所有者吗?,database,go,datatables,owner,yugabyte-db,Database,Go,Datatables,Owner,Yugabyte Db,我已经在我的笔记本电脑上安装了minikube中的yugabytedb,并创建了一个拥有者“Rodgers”的数据库。 然后我运行ysqlsh从终端执行ysql命令,其中一个命令是“创建数据库…” 问题 当我尝试使用外部Go应用程序连接数据库时,通过向应用程序提供用户“Rodgers”和设置的密码,该应用程序无法连接。 我发现创建的表是附在所有者“yugabyte”上的,而不是附在“Rodgers”上的。 但是我连接的数据库以及运行createdatabase命令的位置属于Rodgers 这是怎

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

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


这是怎么回事?

最好用“ysqlsh”排练一下。当一切都在那里工作时,从任何客户端程序(Python、go等)进行连接都会工作—只要您有正确的驱动程序。PostgresSQL驱动程序与YugabyteDB一起工作

下面主要是用于“ysqlsh”的命令——SQLs和所谓的元命令(以反斜杠开头的命令)。但有时,您可以从O/S提示符执行一些命令。因此,您必须仔细阅读下面的内容,然后在每条注释后执行它所说的操作—主要是在“ysqlsh”中,但在O/S提示符下执行几次。因此,您不能简单地运行脚本“lights out”

从virgin YB单节点集群开始(源自“YB创建”)

现在按照脚本进行操作

--  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
-- 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 yugabyte
drop schema public;
\c rog_db rodgers
create 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
--------------------------------------------------------------------------------
再次连接。工作正常

$ ysqlsh -h localhost -p 5433 -d rog_db -U rodgers
现在继续剧本

--  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
-- 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 yugabyte
drop schema public;
\c rog_db rodgers
create 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环境中尝试此功能,然后返回报告


你好,Bryn Llewellyn,Yugabyte Inc.的技术产品经理

非常感谢Bryn。这对我很有用。我爱YugaByteDB。