重庆思庄Oracle、Redhat认证学习论坛
标题:
PG16 创建数据库等相关操作
[打印本页]
作者:
郑全
时间:
2023-11-29 11:33
标题:
PG16 创建数据库等相关操作
1、创建数据库
postgres=# create database testdb;
CREATE DATABASE
2、列出所有数据库
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+------------+------------+------------+-----------+-----------------------
postgres | postgres | UTF8 | libc | zh_CN.UTF8 | zh_CN.UTF8 | | |
template0 | postgres | UTF8 | libc | zh_CN.UTF8 | zh_CN.UTF8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | zh_CN.UTF8 | zh_CN.UTF8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | libc | zh_CN.UTF8 | zh_CN.UTF8 | | |
(4 rows)
3.切换数据库
MYSQL 使用 USE DB_NAME
PG 使用 \c db_name
\c testdb
postgres=# \c testdb
You are now connected to database "testdb" as user "postgres".
4.显示当前连接到哪个数据库
testdb=# \c
You are now connected to database "testdb" as user "postgres".
5.登录到指定数据库
psql -h IP/HOST -p PORT DB_NAME USER
[postgres@dbserver1 pgdata]$ psql -h 127.0.0.1 -p 5432 testdb postgres
psql (16.1)
Type "help" for help.
testdb=#
欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/)
Powered by Discuz! X3.2