/etc/hosts https://blog.csdn.net/tanga842428/article/details/53078643
1. windows版
- 先找到安装包所在路径
路径为:E:\software\postgres\bin
2. 打开cmd,进入这个路径中
3. 运行命令
pg_dump -U redis -f E:/postgres.sql --column-inserts redis
第一个redis是用户名,存放位置E:,名称postgres.sql
最后的redis是实例名
输入密码,生成文件成功,可以去e盘看下文件
2. linux 使用pg_dump
#查看数据库状态,未开启先开启数据库
[postgres@VM_0_3_centos ~]$ pg_ctl status
pg_ctl: server is running (PID: 15868)
/postgres/pgsql/bin/postgres
#下载文件到/tmp目录下
[postgres@VM_0_3_centos ~]$ pg_dump -U ibank -f /tmp/postgres.sql --column-inserts ibank
#查看文件是否生成成功
[postgres@VM_0_3_centos ~]$ cd /tmp
[postgres@VM_0_3_centos tmp]$ ll
total 4132
-rw-r--r-- 1 root root 6917 Jun 9 11:25 cvm_init.log
-rw-r--r-- 1 root root 140 Jun 9 14:19 net_affinity.log
-rw-r--r-- 1 root root 126 Jun 9 11:30 nv_driver_install.log
-rw-r--r-- 1 root root 26 Jun 9 14:19 nv_gpu_conf.log
-rw-rw-r-- 1 postgres postgres 4190360 Jun 10 12:36 postgres.sql
#导出文件到其他数据库,执行命令位置与postgres.sql在同意文件夹下,要不就写全路径
[postgres@VM_0_3_centos ~]$ psql -U ibank -f postgres.sql
备份:
pg_dump -U postgres -d myDBname -f dump.sql
其中
postgres是用户名
myDBname是数据库名
dump.sql是文件名
还原:
createdb newDBname
psql -d newDBname -U postgres -f dump.sql
其中
postgres是用户名
newDBname是数据库名
dump.sql是文件名
导出数据后将数据保存到另一个postgres数据库中,
- 首先新增表空间
- 退出超级用户,创建数据库实例,并指定表空间
postgres=# \q
[postgres@VM_0_3_centos tablespace]$ createdb ibank -D ts_ibank;
- 以超级用户访问ibank数据库,创建user和对应的schema
[postgres@VM_0_3_centos tablespace]$ psql -d ibank
psql (9.5.7)
Type "help" for help.
ibank=# create role ibank login password 'ibank';
CREATE ROLE
ibank=# create schema ibank authorization ibank;
CREATE SCHEMA
如果查到有postgres进程但是pg_ctl status查不到数据,可能是root用户直接启动数据库,没有用postgres用户的pg_ctl 命令;
cd /usr/lib/systemd/system
找到postgres.service文件
systemctl stop postgresql.service
systemctl start postgresql.service
如果psql连接postgres用户可以,其他用户报错:
Postgres psql: FATAL: Peer authentication failed for user “xxx”
需要修改配置文件pg_hba.conf
使用root用户查找文件位置
find / -name pg_hba.conf
local all postgres trust
之后再登陆ibank用户成功,
psql -U ibank -f postgres.sql
导入数据成功