Getting replication lag in PostgreSQL

Here a 2 simple queries to get the replication lag on Postgres servers: select now() – pg_last_xact_replay_timestamp() as lag; select pg_last_xlog_receive_location() receive, pg_last_xlog_replay_location() replay, ( extract(epoch FROM now()) – extract(epoch FROM pg_last_xact_replay_timestamp()) )::int lag;

Installing Postgres 9.4.5 on Ubuntu Trusty

By default on Ubuntu Trusty there is only Postgres 9.3 available This shows how to get the latest version installed. Add the Postgres Repository: echo "deb trusty-pgdg main" > /etc/apt/sources.list.d/postgres.list Import the repository key, and run an update: wget apt-key add ACCC4CF8.asc apt-get update Install Postgres: apt-get install postgresql-9.4