Linux – “Could not create IPv6 socket” postgresql standby error

database-replicationlinuxpostgresqlreplication

I'm trying to create Postgresql 9.1 hot-standby using following steps:

  1. Configured 2 virtual linux machines. Master's ip: 10.10.10.1,
    Standby's ip: 10.10.10.2. Ping test passed.
  2. Restored the same db backup on both.
  3. Edited pg_hba on master. Added line:

    host   replication   postgres   10.10.10.2/32   md5
    
  4. Edited Master's postgresql.conf:

    listen_address = '*'
    wal_level = hot_standby
    max_wal_senders = 3
    
  5. Created recovery.conf on Standby:

    standby_mode = 'on'
    primary_conninfo = 'host=10.10.10.1'
    

After adding recovery.conf I fail to start Standby server. In startup log I get an error:

> could not create IPv6 socket

Did I missed something?

Best Answer

This happens when IPv6 is not enabled in the kernel but IPv6 addresses are advertised somewhere.

Sometimes localhost in /etc/hosts designates both 127.0.0.1 (IPv4) and ::1 (IPv6). In which case you may remove the IPv6 alias to avoid that kind of error.

The stats collector (a separate process launched by PostgreSQL) uses the hard-coded name localhost, so this problem would make it fail to start with the mentioned error message. However, this shouldn't prevent PostgreSQL itself to start.

If * happens to include problematic IPv6 addresses, you may solve the problem by being selective in listen_addresses (which is good practice anyway):

listen_addresses=127.0.0.1,10.10.10.1 # add other interfaces if needed