问题描述
我启动了一个postgres容器。它通过放置在docker-entrypoint文件夹中的.sql文件创建模式和表。我的架构在\dn +中列出。但是\dt没有关系。
I have launched a postgres container. It creates Schemas and tables through .sql file placed in docker-entrypoint folder. My schema is listed in \dn+. But \dt gives no relations. Access Privileges are intact.
执行\dn +会给出:
List of schemas:
Name | Owner | Access privileges | Description
--------+----------+----------------------+------------------------
MYAPP | postgres | |
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
做\dt会得到:(在公共模式中)
Did not find any relations.
但是我的.sql文件可以在同一数据库内的公共模式下创建表。 \dt正确显示了表列表。
However my .sql file can create tables inside public schema inside same DB. And \dt shows list of tables correctly.
为什么我不能在非公共模式下创建表。
Why I am not able to create tables inside non-public schema . Any privilege constraints?
sql内容如下:
CREATE SCHEMA "MYAPP";
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA MYAPP TO postgres;
CREATE TABLE "MYAPP"."ACCESS_MASTER" ("ACCESS_ID" character varying COLLATE pg_catalog."default" NOT NULL,"ROLE_ID" character varying COLLATE pg_catalog."default");
这是怎么了?请指导。
编辑:
IMCDB =#\dn
IMCDB=# \dn
List of schemas
Name | Owner
--------+----------
MYAPP | postgres
public | postgres
(2 rows)
MYAPP=# \dt
Did not find any relations.
IMCDB=# set search_path="MYAPP";
SET
MYAPP=# \dt
Did not find any relations.
MYAPP=# show search_path;
search_path
-------------
"MYAPP"
(1 row)
MYAPP=# \dt
Did not find any relations.
MYAPP=#
设置架构的路径也无济于事。
Setting the path to my schema didn't help too.
推荐答案
\dt仅列出默认模式中存在的关系,默认关系在您的情况下是公开的。
\dt will only list relations that are present in your default schema which is public in your case.
您需要对MYAPP设置search_path,之后,它将列出存在于MYAPP模式中的所有关系。
You need to SET search_path to MYAPP, after that, it will list all relations present in schema MYAPP.
postgres=# show search_path;
LOG: statement: show search_path;
search_path
-----------------
"$user", public
(1 row)
postgres=# set search_path="MYAPP";
SET
postgres=# show search_path;
search_path
-------------
"MYAPP"
(1 row)
披露:我为
这篇关于无法查看创建的架构内的任何关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!