postgresql跟踪计数和autovacuum不起作用

在启动日志条目指示autovacuum不工作。 我查询了pg_stat_user_tables表,last_vacuum和last_autovacuum列是空的,尽pipe我之前运行的是真空查询。 将pgadmin连接到数据库会提示真空不起作用。

我在两个Ubuntu Azure虚拟机上使用postgresql。 一台虚拟机设置为主设备,另一台虚拟机通过stream式传输方式复制数据库。 粗略地描述在https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-on-postgresql-on-an-ubuntu-12-04-vps 。

除了自动清理,似乎所有的工作都是如此。 在启动过程中logging以下错误:

LOG: test message did not get through on socket for statistics collector LOG: disabling statistics collector for lack of working socket WARNING: autovacuum not started because of misconfiguration HINT: Enable the "track_counts" option. LOG: database system was shut down at 2017-01-19 14:07:13 UTC DEBUG: checkpoint record is at 38/F6000028 

在postgresql.config中,我使用以下设置:

 track_counts = on autovacuum = on log_autovacuum_min_duration = 200 autovacuum_max_workers = 1 autovacuum_naptime =960 autovacuum_vacuum_threshold = 128 autovacuum_analyze_threshold = 256 

在数据库上查询(从pg_stat_user_tables中select*)以查找最后(自动)真空,为最后(自动)真空提供空柱而不是date时间。 就在我跑完VACUUM FULL VERBOSE之前 这给了我真空的结果。

如果我查询真空设置:

 select * from pg_settings where name like 'autovacuum%' 

这是结果:

 "autovacuum";"on"<br /> "autovacuum_analyze_scale_factor";"0.1" "autovacuum_analyze_threshold";"256" "autovacuum_freeze_max_age";"200000000" "autovacuum_max_workers";"1"<br /> "autovacuum_multixact_freeze_max_age";"400000000" "autovacuum_naptime";"960"<br /> "autovacuum_vacuum_cost_delay";"20" "autovacuum_vacuum_cost_limit";"-1" "autovacuum_vacuum_scale_factor";"0.2" "autovacuum_vacuum_threshold";"128" "autovacuum_work_mem";"-1" 

这些是'track_'结果:

 "track_activities";"on" "track_activity_query_size";"1024" "track_commit_timestamp";"off" "track_counts";"off" "track_functions";"none" "track_io_timing";"off" 

pg_hba.conf(没有复制和networking/用户设置)如下所示:

 local all all trust host all all localhost trust host all all 10.1.1.5/32 md5 host all all 127.0.0.1/32 md5 host all all 0.0.0.0 0.0.0.0 md5 

/ etc / hosts:

 127.0.0.1 localhost 127.0.1.1 ubuntu ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts 

这是'netstat -ant | grep 5432'的结果,如果清理和格式化。

 User@Machine:/datadrive/log/postgresql/pg_log$ netstat -ant|grep 5432 tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN tcp 39 0 InternIpMaster:5432 InternIpSlave:36338 ESTABLISHED tcp 0 0 InternIpMaster:5432 IpJob:63814 TIME_WAIT tcp 0 0 InternIpMaster:5432 IpJob:22192 TIME_WAIT tcp 0 0 InternIpMaster:5432 IpJob:47729 TIME_WAIT tcp 0 0 InternIpMaster:5432 IpJob:55663 TIME_WAIT tcp6 0 0 :::5432 :::* LISTEN 

我不希望autovacuum需要工作,因为

所以在启动期间,track_counts在运行时被禁用。

我一直在寻找改变iptables的解决scheme。 没有任何iptable规则,它将无法正常工作。 我已经连接到本地主机。 我已经更改了Azure中的防火墙设置。 我打开5432访问从所有IP的虚拟机。 我能够从其他系统访问数据库。 我已经将conf重置为仅有复制更改的默认值。 我多次重新启动服务。

我错过了什么?

你想解决这个问题:

日志:testing消息没有通过套接字统计收集器
日志:禁用统计收集器缺乏工作套接字

统计收集器期望来自本地主机的UDP数据包。 考虑到在/etc/hosts localhost看起来不错(特别是它不parsing为IPv6),下一个更合理的解释是有一个防火墙过滤这些数据包。

相关: 创buildUDP套接字问题解决了: find并解决了创buildUDP套接字的问题。 这是因为操作系统防火墙(iptables)在创buildUDP套接字方面受到限制。

我想详细说明@Daniel给出的答案和解决我的问题的方法。

我已经build立了iptables为了获得访问postgresql像这样:

 sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT sudo iptables -A INPUT -i lo -j ACCEPT sudo iptables -A OUTPUT -o lo -j ACCEPT sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT sudo iptables -A INPUT -j DROP 

我认为这是很多。 但是,当我使用sudo iptables --flush并重新启动postgres服务器时,由于缺less工作套接字而导致禁用统计信息收集器的错误消失了。

我也用iptraf来调查stream量( sudo apt-get install iptraf sudo iptraf )。 我注意到一个stream量源于服务器的IP本地(子网)地址,但在不同的端口。 这是从机上的stream量(没有azure色的stream量)。

 SubnetIpSlave:22 SubnetIpSlave:45622 SubnetIpSlave:44770 SubnetIpSlave:48948 SubnetIpMaster:5432 

我认为这个stream量是由iptables阻止的,因为它不会通过回送。 所以我清理了iptables。 这是结果:

 sudo iptables -A INPUT -i lo -j ACCEPT sudo iptables -A OUTPUT -o lo -j ACCEPT sudo iptables -A INPUT -p icmp -j ACCEPT sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 5432 -j ACCEPT sudo iptables -A INPUT -s 10.1.1.0/24 -j ACCEPT sudo iptables -A INPUT -j DROP 

我包括子网。 我认为这是它的工作原理,因为SubnetIpSlave和SubnetIpMaster都在这个范围内。 我可能被允许删除ESTABLISHED,RELATED规则。

日志看起来应该是这样的:

 2017-01-24 09:19:38 UTC [1482-1] LOG: database system was shut down in recovery at 2017-01-24 09:17:41 UTC 2017-01-24 09:19:38 UTC [1483-1] [unknown]@[unknown] LOG: incomplete startup packet 2017-01-24 09:19:38 UTC [1482-2] LOG: entering standby mode 2017-01-24 09:19:38 UTC [1482-3] DEBUG: checkpoint record is at 5D/F2042CA8 

我很开心 ;)

根据你的链接, You should now be able to ssh freely between your two servers as the postgres user. 所以,你需要为postgres用户build立从master到slave的信任关系,从master到master。

您可以使用ssh-keygen来创build一个密码为空的密钥对。

shui@shui:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/shui/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/shui/.ssh/id_rsa. Your public key has been saved in /home/shui/.ssh/id_rsa.pub. The key fingerprint is: SHA256:mCyBHNLeEdCH2VqBjhtOC8njVLSXnjU7V9GbufK+hlE shui@shui The key's randomart image is: +---[RSA 2048]----+ |..++.*.. .. | | o.+B = .. | |.o+=.B o . + | |o+= *oooo . E | |o+.+.o+oS. . . | | .+ . oo . | | = | | . o | | oo. | +----[SHA256]-----+ shui@shui:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/shui/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/shui/.ssh/id_rsa. Your public key has been saved in /home/shui/.ssh/id_rsa.pub. The key fingerprint is: SHA256:mCyBHNLeEdCH2VqBjhtOC8njVLSXnjU7V9GbufK+hlE shui@shui The key's randomart image is: +---[RSA 2048]----+ |..++.*.. .. | | o.+B = .. | |.o+=.B o . + | |o+= *oooo . E | |o+.+.o+oS. . . | | .+ . oo . | | = | | . o | | oo. | +----[SHA256]-----+更多信息请参考此链接 。

另外,您需要在Azure NSG上打开端口5432。