gpt4 book ai didi

postgresql - 如何断开与数据库的连接并返回到 PostgreSQL 中的默认数据库?

转载 作者:行者123 更新时间:2023-11-29 11:05:30 27 4
gpt4 key购买 nike

我正在使用 PostgreSql 版本:

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

我已经连接到一个数据库,从 postgres=#newdb=#....现在我在 newdb=# 数据库中,我想断开它并返回到 postgres=# 数据库....

如何做到这一点?

我试过 disconnect newdb;

但它给出了 erroe as::

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=#

它不起作用是否有任何其他方法可以做到这一点,或者我有什么不对的地方!!

最佳答案

很简单,看例子。

--我的数据库

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)

--切换到db francs作为角色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=#

--断开与数据库的连接

postgres=# \q

关于postgresql - 如何断开与数据库的连接并返回到 PostgreSQL 中的默认数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17963348/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com