本文介绍了如何断开数据库连接并返回到PostgreSQL中的默认数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PostgreSql版本:
I'm using PostgreSql version :
postgres=# select version();
version
-------------------------------------------------------------
PostgreSQL 9.2.4, compiled by Visual C++ build 1600, 64-bit
(1 row)
我已从 postgres =#
连接到数据库 newdb =#
....
现在我在 newdb =#
数据库中,我想断开连接并返回到 postgres =#
数据库...。
i had connected to a database from postgres=#
to newdb=#
....Now i'm in newdb=#
Database i want to disconnect it and go back to postgres=#
database ....
如何执行此操作?
我尝试用 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=#
它没有用吗?这样做还是我在任何事情上都错了!
it isnt working is there any other way to do this or am i wrong in anything!!
推荐答案
很简单,只看示例。
-我的数据库
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)
-切换到数据库francs作为角色francs
postgres=# \c francs francs
You are now connected to database "francs" as user "francs".
-以db postgres身份作为角色postgres
francs=> \c postgres postgres
You are now connected to database "postgres" as user "postgres".
postgres=#
-与数据库断开连接
postgres=# \q
这篇关于如何断开数据库连接并返回到PostgreSQL中的默认数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!