我使用的是PostgreSql版本:

postgres=# select version();
                           version
-------------------------------------------------------------
 PostgreSQL 9.2.4, compiled by Visual C++ build 1600, 64-bit
(1 row)

我连接了一个从postgres=#newdb=#的数据库....

怎么做?

我试过disconnect newdb;次了

但它给了埃罗:

postgres=# create database newdb;
CREATE DATABASE
postgres=# \c newdb;
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
You are now connected to database "newdb" as user "postgres".
newdb=# disconnect newdb;
ERROR:  syntax error at or near "disconnect"
LINE 1: disconnect newdb;
        ^
newdb=#

这是行不通的,有没有其他方法可以做到这一点,或者我做错了什么!!

推荐答案

这很简单,只要看看这个例子.

--my databases

postgres=# \l
                               List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |     Access privileges     
-----------+----------+----------+---------+-------+---------------------------
 francs    | postgres | UTF8     | C       | C     | =Tc/postgres             +
           |          |          |         |       | postgres=CTc/postgres    +
           |          |          |         |       | francs=C*T*c*/postgres   +
           |          |          |         |       | select_only=c/francs
 postgres  | postgres | UTF8     | C       | C     | 
 source_db | postgres | UTF8     | C       | C     | =Tc/postgres             +
           |          |          |         |       | postgres=CTc/postgres    +
           |          |          |         |       | source_db=C*T*c*/postgres
 template0 | postgres | UTF8     | C       | C     | =c/postgres              +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres              +
           |          |          |         |       | postgres=CTc/postgres
(5 rows)

--switch to db francs as role francs

postgres=# \c francs francs
You are now connected to database "francs" as user "francs".

--swith to db postgres as role postgres

francs=> \c postgres postgres

You are now connected to database "postgres" as user "postgres".
postgres=# 

--disconnect from db

postgres=# \q

Postgresql相关问答推荐

使用regexp获取表名

通过窗口函数收集反连接结果?

对 VOLATILE 函数的调用会 destruct SELECT 语句的原子性

我想优化查询SQL

对 Postgres 进行身份验证时如何使用自定义密码哈希算法?

将 postgres 从属提升为主 node

PostgreSQL - 如何获得前一个月和一周的价值?

无法从在 wsl 2 上运行的服务之一连接到在 wsl 2 上的容器中运行的 postgres 数据库

PostgreSQL错误致命:角色 username不存在

PostgreSQL 在 mySQL 中的 date_trunc

SQL数据库表中的多态性?

IntegrityError:postgres 从转储恢复后,所有具有 ForeignKey 的模型/字段的id列中的空值

为什么 sqlalchemy 的默认列值不起作用

如何在数据库表中查找重复条目?

使用 PostgreSQL 创建数据透视表

如何为 Postgres psql 设置时区?

使用 PostgreSQL 的 Linq To Sql

如何使用 postgresql 按计数排序?

如何在postgres中将整数分钟转换为间隔

postgres LISTEN/NOTIFY rails