我有一个具有多个模式的postgres数据库。当我用psql从shell连接到数据库并运行\dt时,它使用默认的公共连接模式。是否有可以指定的标志或如何更改模式?
当前回答
这是旧的,但我把导出放在我的别名连接到db:
alias schema_one.con="PGOPTIONS='--search_path=schema_one' psql -h host -U user -d database etc"
对于另一个schema:
alias schema_two.con="PGOPTIONS='--search_path=schema_two' psql -h host -U user -d database etc"
其他回答
这是旧的,但我把导出放在我的别名连接到db:
alias schema_one.con="PGOPTIONS='--search_path=schema_one' psql -h host -U user -d database etc"
对于另一个schema:
alias schema_two.con="PGOPTIONS='--search_path=schema_two' psql -h host -U user -d database etc"
在psql命令中使用带句点的模式名获取该模式的信息。
设置:
test=# create schema test_schema;
CREATE SCHEMA
test=# create table test_schema.test_table (id int);
CREATE TABLE
test=# create table test_schema.test_table_2 (id int);
CREATE TABLE
显示test_schema中的关系列表:
test=# \dt test_schema.
List of relations
Schema | Name | Type | Owner
-------------+--------------+-------+----------
test_schema | test_table | table | postgres
test_schema | test_table_2 | table | postgres
(2 rows)
显示test_schema。test_table定义:
test=# \d test_schema.test_table
Table "test_schema.test_table"
Column | Type | Modifiers
--------+---------+-----------
id | integer |
显示test_schema中的所有表:
test=# \d test_schema.
Table "test_schema.test_table"
Column | Type | Modifiers
--------+---------+-----------
id | integer |
Table "test_schema.test_table_2"
Column | Type | Modifiers
--------+---------+-----------
id | integer |
等等……
要更改数据库吗?
\l - to display databases
\c - connect to new database
更新。
我又看了一遍你的问题。 显示模式
\dn - list of schemas
要改变模式,您可以尝试
SET search_path TO
关键词:
SET search_path TO
例子:
SET search_path TO your_schema_name;
快速解决方案可以是:
SELECT your_db_column_name from "your_db_schema_name"."your_db_tabel_name";
推荐文章
- 将varchar字段的类型更改为整数:"不能自动转换为整数类型"
- PostgreSQL可以索引数组列吗?
- PostgreSQL:角色不允许登录
- 如何查找Postgres / PostgreSQL表及其索引的磁盘大小
- 是使用各有一个模式的多个数据库更好,还是使用一个数据库有多个模式更好?
- 如果字符串包含
- 对于PostgreSQL表来说,多大才算太大?
- 将一列的多个结果行连接为一列,按另一列分组
- 使用pgadmin连接到heroku数据库
- 在PostgreSQL中快速发现表的行数
- 更改varchar列的大小为较低的长度
- 如何首次配置postgresql ?
- 数据库性能调优有哪些资源?
- 如何在PostgreSQL中自动更新时间戳
- 当使用JDBC连接到postgres时,是否可以指定模式?