ITPub博客

首页 > 数据库 > PostgreSQL > PG基础:PG数据库创建

PG基础:PG数据库创建

原创 PostgreSQL 作者:tompson666 时间:2024-04-17 20:38:03 0 删除 编辑

1.创建数据库

TEMPLATE1=# create database dbtom owner tom tablespace ts_data;
CREATE DATABASE
Time: 328.663 ms

2.创建数据库指定字符集UTF8

create database dbtom owner tom  ENCODING 'UTF8';



3.从模板创建数据库


create database templatedb template template0;



4.查看数据库

TEMPLATE1=# \l
                                List of databases
   Name    |  Owner   | Encoding | Collate |    Ctype    |   Access privileges   
-----------+----------+----------+---------+-------------+-----------------------
 DBTOM     | TOM      | UTF8     | C       | zh_CN.UTF-8 | 
 POSTGRES  | GAUSSDBA | UTF8     | C       | zh_CN.UTF-8 | 
 TEMPLATE0 | GAUSSDBA | UTF8     | C       | zh_CN.UTF-8 | =c/GAUSSDBA          +
           |          |          |         |             | GAUSSDBA=CTc/GAUSSDBA
 TEMPLATE1 | GAUSSDBA | UTF8     | C       | zh_CN.UTF-8 | =c/GAUSSDBA          +
           |          |          |         |             | GAUSSDBA=CTc/GAUSSDBA
(4 rows)
postgres=# \l+
                                                                 List of databases
    Name    |   Owner    | Encoding  | Collate | Ctype |   Access privileges   |  Size   | Tablespace |                Description
------------+------------+-----------+---------+-------+-----------------------+---------+------------+--------------------------------------------
 db_corrupt | db_corrupt | SQL_ASCII | C       | C     |                       | 8049 kB | pg_default |
 db_tom     | postgres   | SQL_ASCII | C       | C     |                       | 8337 kB | s


5.切换数据库

TEMPLATE1=# \c dbtom
You are now connected to database "DBTOM".
DBTOM=#



6.从操作系统链接数据库

[gaussdba@hwcmdb data]$ gsql -d dbtom
gsql (9.2.4)
Type "help" for help.



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70038077/viewspace-3012861/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: PG与gdb core
请登录后发表评论 登录
全部评论
Oracle ACE PostgreSQL ACE PG/MySQL内核技术推广者 著有《Oracle高性能自动化运维》 目前致力于Oracle/MySQL/PG技术推广&信创项目交付&最佳实践探索。公众号:dba悠然

注册时间:2024-04-14

  • 博文量
    42
  • 访问量
    33731