postgresql数据库导入导出

一、常规操作

1、进入数据库

psql -h localhost -p 5432 -U kong

2、查看库

复制代码
kong=# \l
                             List of databases
   Name    | Owner | Encoding |  Collate   |   Ctype    | Access privileges 
-----------+-------+----------+------------+------------+-------------------
 kong      | kong  | UTF8     | en_US.utf8 | en_US.utf8 | 
 konga     | kong  | UTF8     | en_US.utf8 | en_US.utf8 | 
 postgres  | kong  | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0 | kong  | UTF8     | en_US.utf8 | en_US.utf8 | =c/kong          +
           |       |          |            |            | kong=CTc/kong
 template1 | kong  | UTF8     | en_US.utf8 | en_US.utf8 | =c/kong          +
           |       |          |            |            | kong=CTc/kong
(5 rows)
复制代码

3、切换到库

kong-# \c kong
You are now connected to database "kong" as user "kong".

4、查看表

复制代码
kong-# \d
                   List of relations
 Schema |             Name              | Type  | Owner 
--------+-------------------------------+-------+-------
 public | acls                          | table | kong
 public | acme_storage                  | table | kong
 public | basicauth_credentials         | table | kong
 public | ca_certificates               | table | kong
 public | certificates                  | table | kong
 public | cluster_events                | table | kong
 public | clustering_data_planes        | table | kong
 public | consumers                     | table | kong
 public | hmacauth_credentials          | table | kong
 public | jwt_secrets                   | table | kong
 public | keyauth_credentials           | table | kong
 public | locks                         | table | kong
 public | oauth2_authorization_codes    | table | kong
 public | oauth2_credentials            | table | kong
复制代码

5、退出

kong-# \q

 

二、导出数据库

pg_dump -U kong kong > kong.sql
pg_dump -U kong konga > konga.sql

三、导入数据库

psql -U kong < kong.sql
psql -U konga < konga.sql
posted @   awks  阅读(1401)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示