我希望有一个单独的用户和rw-access的单独数据库:
postgres=# \l
-[ RECORD 3 ]-----+----------------------------
Name | report
Owner | report
Encoding | UTF8
Collate | en_US.UTF-8
Ctype | en_US.UTF-8
Access privileges | =T/report +
| report=CTc/report
postgres=# \du
Role name | report
Attributes |
Member of | {}
现在出现了问题:
report=> \c report
You are now connected to database "report" as user "report".
report=> CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
ERROR: no schema has been selected to create in
LINE 1: CREATE TABLE COMPANY(
^
所以我试着查看了模式:
report=> \dn+
List of schemas
-[ RECORD 1 ]-----+------------------------
Name | public
Owner | postgres
Access privileges | postgres=UC/postgres +
Description | standard public schema
我想知道为什么创建的角色没有列出。我有一些其他数据库和帐户,这可以正常工作。我刚从剪辑中删除了它们。 这是搜索路径:
report=> show search_path;
-[ RECORD 1 ]----------------
search_path | "$user", public
我认为问题在于,报表用户不是公共架构的一部分。我怎么能加他?
更新1
我遵循了建议并做了
postgres=> GRANT CREATE, USAGE ON SCHEMA public TO report;
postgres=# \dn+
List of schemas
-[ RECORD 1 ]-----+------------------------
Name | public
Owner | postgres
Access privileges | postgres=UC/postgres +
| report=UC/postgres
Description | standard public schema
但是当我使用报告登录时,我得到以下结果:
report=> \dn+
List of schemas
-[ RECORD 1 ]-----+------------------------
Name | public
Owner | postgres
Access privileges | postgres=UC/postgres +
Description | standard public schema
更新2
以下是第二条建议的输出:
postgres=# SELECT nspname, nspname::bytea
postgres-# FROM pg_namespace
postgres-# WHERE nspname LIKE '%public%';
-[ RECORD 1 ]-----------
nspname | public
nspname | \x7075626c6963
更新3
report=> set search_path to public;
SET
report=> CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
ERROR: no schema has been selected to create in
LINE 1: CREATE TABLE COMPANY(
^
report=> CREATE TABLE public.COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
ERROR: permission denied for schema public
LINE 1: CREATE TABLE public.COMPANY(
亲切的问候