分享PostgreSQL数据库导入和导出脚本

树叶云

PostgreSQL (也叫 Postgres)是一个自由的对象-关系数据库服务器(数据库管理系统)。它提供了相对其他开放源代码数据库系统(比如 MySQL 和 Firebird),和对专有系统比如 Oracle、Sybase、IBM 的 DB2 和 Microsoft SQL Server的一种选择。

导出

/usr/bin/pg_dump -U postgres testdb > /home/app/testdb`date +%Y%m%d`.sql

cd /home/app

gzip testdb`date +%Y%m%d`.sql

导入

day=`date +%Y%m%d`

drop database testdb;//删除原来的库

CREATE DATABASE testdb;

psql -U postgres -d testdb -f /home/app/testdb${day}.sql

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/221242.html<

(0)
运维的头像运维
上一篇2025-04-14 22:52
下一篇 2025-04-14 22:53

相关推荐

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注