pg归档日志的开启与关闭
2017-10-09 20:43
513 查看
postgres.conf文件的配置对所有数据库起作用:
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------------+----------+-------------+-------------+---------------------------------
postgres | postgres9.6 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres9.6 | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/"postgres9.6" +
| | | | | "postgres9.6"=CTc/"postgres9.6"
template1 | postgres9.6 | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/"postgres9.6" +
| | | | | "postgres9.6"=CTc/"postgres9.6"
test | postgres9.6 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)
postgres=# \c
You are now connected to database "postgres" as user "postgres9.6".
postgres=# show archive_mode;
archive_mode
--------------
on
(1 row)
postgres=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/C000078
(1 row)
test=# \c
You are now connected to database "test" as user "postgres9.6".
test=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/B02A090
(1 row)
[root@db 20170206]# pwd
/home/postgres9.6/arch/20170206
[root@db 20170206]# ls
00000001000000000000000A 00000001000000000000000B 00000001000000000000000C
============================================================================================================================
开启归档模式:
[postgres9.6@db data]$ pwd
/home/postgres9.6/data
[postgres9.6@db data]$ ll postgresql.conf
-rw------- 1 postgres9.6 postgres 22369 Feb 6 13:35 postgresql.conf
vi postgres.conf修改如下:
wal_level = replica # minimal, replica, or logical
archive_mode = on # enables archiving; off, on, or always
# (change requires restart)
archive_command = 'DATE=`date +%Y%m%d`;DIR="/home/postgres9.6/arch/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f' # command to use to archive a logfile segment
其中: %p表示wal日志文件的路径,%f表示wal日志文件名称。
[postgres9.6@db data]$ pg_ctl stop
waiting for server to shut down.... done
server stopped
[postgres9.6@db data]$ pg_ctl start
server starting
[postgres9.6@db data]$ LOG: database system was shut down at 2017-02-06 13:40:26 CST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
postgres=# \c
You are now connected to database "postgres" as user "postgres9.6".
postgres=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/F000120
(1 row)
postgres=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/10000078
(1 row)
postgres=# show archive_mode;
archive_mode
--------------
on
(1 row)
test=# \c
You are now connected to database "test" as user "postgres9.6".
test=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/11000078
(1 row)
test=# show archive_mode;
archive_mode
--------------
on
(1 row)
[root@db 20170206]# pwd
/home/postgres9.6/arch/20170206
[root@db 20170206]# ls
00000001000000000000000F 000000010000000000000010 000000010000000000000011
##### pg里不同数据库之间日志(归档日志或者pc_xlog)(目录)是共享的。####
关闭归档模式:
将以上三个参数注释或者修改即可
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------------+----------+-------------+-------------+---------------------------------
postgres | postgres9.6 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres9.6 | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/"postgres9.6" +
| | | | | "postgres9.6"=CTc/"postgres9.6"
template1 | postgres9.6 | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/"postgres9.6" +
| | | | | "postgres9.6"=CTc/"postgres9.6"
test | postgres9.6 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)
postgres=# \c
You are now connected to database "postgres" as user "postgres9.6".
postgres=# show archive_mode;
archive_mode
--------------
on
(1 row)
postgres=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/C000078
(1 row)
test=# \c
You are now connected to database "test" as user "postgres9.6".
test=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/B02A090
(1 row)
[root@db 20170206]# pwd
/home/postgres9.6/arch/20170206
[root@db 20170206]# ls
00000001000000000000000A 00000001000000000000000B 00000001000000000000000C
============================================================================================================================
开启归档模式:
[postgres9.6@db data]$ pwd
/home/postgres9.6/data
[postgres9.6@db data]$ ll postgresql.conf
-rw------- 1 postgres9.6 postgres 22369 Feb 6 13:35 postgresql.conf
vi postgres.conf修改如下:
wal_level = replica # minimal, replica, or logical
archive_mode = on # enables archiving; off, on, or always
# (change requires restart)
archive_command = 'DATE=`date +%Y%m%d`;DIR="/home/postgres9.6/arch/$DATE";(test -d $DIR || mkdir -p $DIR)&& cp %p $DIR/%f' # command to use to archive a logfile segment
其中: %p表示wal日志文件的路径,%f表示wal日志文件名称。
[postgres9.6@db data]$ pg_ctl stop
waiting for server to shut down.... done
server stopped
[postgres9.6@db data]$ pg_ctl start
server starting
[postgres9.6@db data]$ LOG: database system was shut down at 2017-02-06 13:40:26 CST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
postgres=# \c
You are now connected to database "postgres" as user "postgres9.6".
postgres=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/F000120
(1 row)
postgres=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/10000078
(1 row)
postgres=# show archive_mode;
archive_mode
--------------
on
(1 row)
test=# \c
You are now connected to database "test" as user "postgres9.6".
test=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/11000078
(1 row)
test=# show archive_mode;
archive_mode
--------------
on
(1 row)
[root@db 20170206]# pwd
/home/postgres9.6/arch/20170206
[root@db 20170206]# ls
00000001000000000000000F 000000010000000000000010 000000010000000000000011
##### pg里不同数据库之间日志(归档日志或者pc_xlog)(目录)是共享的。####
关闭归档模式:
将以上三个参数注释或者修改即可
相关文章推荐
- Oracle 11G RAC开启和关闭归档日志
- Oracle单节点开启关闭归档日志
- oracle 开启关闭归档日志
- Oracle 开启归档日志以及关闭归档日志
- oracle 开启关闭归档日志
- Oralce 归档日志开启与关闭示例
- 【识记】spfile迁往共享存储,关闭审计,开启归档日志和查看休息连接数等2013.4.27
- Oracle 开启归档日志以及关闭归档日志
- Oracle关闭和开启归档日志
- Oralce 归档日志开启与关闭
- oracle 开启关闭归档日志
- oracle 归档日志开启,关闭
- Oracle关闭和开启归档日志
- oracle 归档日志开启、关闭及删除归档日志
- Oracle 11G RAC开启和关闭归档日志
- oracle归档日志的开启和关闭
- Oralce 归档日志开启与关闭示例
- oracle 关闭和开启归档日志
- Oracle11g RAC开启关闭、设置归档小结
- oracle RAC--归档日志的开启方法