londiste ERROR Node 'slave_IP' already exists - postgresql

Yesterday, i used londiste for logical replication between PostgreSQL 9.3 and 9.5
Today, i try use londiste again. But i dont deleted node, schema after use londiste yesterday.
List package
yum list skytools*
Installed Packages
skytools-95.x86_64 3.2.6-1.rhel7
skytools-95-modules.x86_64 3.2.6-1.rhel7
Config master
cat /etc/skytools/londiste-master.ini
[londiste3]
job_name = appqueue
db = dbname=my_database host=master_IP
queue_name = appqueue
logfile = /var/log/skytools/master.log
pidfile = /var/run/skytools/master.pid
Config Slave
cat /etc/skytools/londiste-slave.ini
[londiste3]
job_name = appqueue
db = dbname=my_database
queue_name = appqueue
logfile = /var/log/skytools/slave.log
pidfile = /var/run/skytools/slave.pid
You have mail in /var/spool/mail/root
Install scheme
qadmin -h master_IP -U postgres -d my_database -c "install londiste"
INSTALL
Copy DB
pg_dump -h master_IP -s -C -U postgres my_database |psql -U postgres
create-root master_IP
su postgres -c "londiste3 /etc/skytools/londiste-master.ini create-root master_IP 'dbname=my_database host=master_IP'"
2017-10-27 08:36:16,250 20249 INFO plpgsql is installed
2017-10-27 08:36:16,250 20249 INFO pgq is installed
2017-10-27 08:36:16,252 20249 INFO pgq.get_batch_cursor is installed
2017-10-27 08:36:16,252 20249 INFO pgq_ext is installed
2017-10-27 08:36:16,253 20249 INFO pgq_node is installed
2017-10-27 08:36:16,254 20249 INFO londiste is installed
2017-10-27 08:36:16,254 20249 INFO londiste.global_add_table is installed
2017-10-27 08:36:16,262 20249 INFO Node is already initialized as root
create-leaf slave_IP
su postgres -c "londiste3 /etc/skytools/londiste-slave.ini create-leaf slave_IP dbname=my_database --provider='host=master_IP dbname=my_database'"
2017-10-27 08:37:10,984 20414 WARNING No host= in public connect string, bad idea
2017-10-27 08:37:10,991 20414 INFO plpgsql is installed
2017-10-27 08:37:10,992 20414 INFO pgq is installed
2017-10-27 08:37:10,993 20414 INFO pgq.get_batch_cursor is installed
2017-10-27 08:37:10,993 20414 INFO pgq_ext is installed
2017-10-27 08:37:10,994 20414 INFO pgq_node is installed
2017-10-27 08:37:10,994 20414 INFO londiste is installed
2017-10-27 08:37:10,994 20414 INFO londiste.global_add_table is installed
2017-10-27 08:37:11,006 20414 INFO Initializing node
2017-10-27 08:37:11,022 20414 ERROR Node 'slave_IP' already exists
Run londiste3 master and slave worker
su postgres -c "londiste3 -d /etc/skytools/londiste-slave.ini worker"
Ignoring stale pidfile
su postgres -c "londiste3 -d /etc/skytools/londiste-master.ini worker"
Ignoring stale pidfile
Run pgqd
pgqd -d /etc/skytools/pgqd.ini
2017-10-27 08:38:31.638 20659 LOG Starting pgqd 3.2.6
Master status
su postgres -c "londiste3 /etc/skytools/londiste-master.ini status"
Queue: appqueue Local node: master_IP
None (None)
Tables: 0/0/0
Lag: (n/a), NOT UPTODATE
master_IP (root)
Tables: 0/0/0
Lag: 17h56m7s, Tick: 1
Try Delete node:
su postgres -c "londiste3 /etc/skytools/londiste-slave.ini drop-node slave_IP"
2017-10-27 09:20:50,945 29464 ERROR get_node_database: cannot resolve slave_IP
su postgres -c "londiste3 /etc/skytools/londiste-slave.ini drop-node slave_IP dbname=my_database"
2017-10-27 09:21:17,859 29543 ERROR command 'drop-node' got 2 args, but expects 1: node_name
su postgres -c "londiste3 /etc/skytools/londiste-master.ini drop-node master_IP"
2017-10-27 09:24:32,038 30190 ERROR node still has subscribers
How correct fix this error?
Package don`t have application pgqadm.py

You must use the name you gave the node, not its ip.
for example if you create the node
londiste3 slave.ini create-branch slave 'SLAVE_CONN_STR' --provider = 'MASTER_CONN_STR'
you delete the node with
londiste3 slave.ini drop-node slave

Related

Why does my postgresql+repmgr+timescaledb container stop right after start up?

I was trying to build an customized image of postgresql+repmgr+timescaledb on docker.
Here is my dockerfile:
FROM bitnami/postgresql-repmgr:12.4.0-debian-10-r90
USER root
RUN apt-get update \
&& apt-get -y install \
gcc cmake git clang-format clang-tidy openssl libssl-dev \
&& git clone https://github.com/timescale/timescaledb.git
RUN cd timescaledb \
&& git checkout 2.8.1 \
&& ./bootstrap -DREGRESS_CHECKS=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
&& cd build \
&& make \
&& make install
RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen
USER 1001
build command:
docker build -f dockerfile -t my/pg-repmgr-12-tsdb:12.4.0-debian-10-r90 .
When I tested it, it ran perfectly for the primary node, but when I tried to establish a stand by node, the instance stopped almost immediately after starting up and leaving the logs to be:
postgresql-repmgr 18:51:11.00
postgresql-repmgr 18:51:11.00 Welcome to the Bitnami postgresql-repmgr container
postgresql-repmgr 18:51:11.00 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql-repmgr
postgresql-repmgr 18:51:11.00 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql-repmgr/issues
postgresql-repmgr 18:51:11.01
postgresql-repmgr 18:51:11.03 INFO ==> ** Starting PostgreSQL with Replication Manager setup **
postgresql-repmgr 18:51:11.05 INFO ==> Validating settings in REPMGR_* env vars...
postgresql-repmgr 18:51:11.06 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql-repmgr 18:51:11.06 INFO ==> Querying all partner nodes for common upstream node...
postgresql-repmgr 18:51:11.13 INFO ==> Auto-detected primary node: 'pg-0:5432'
postgresql-repmgr 18:51:11.14 INFO ==> Preparing PostgreSQL configuration...
postgresql-repmgr 18:51:11.14 INFO ==> postgresql.conf file not detected. Generating it...
postgresql-repmgr 18:51:11.26 INFO ==> Preparing repmgr configuration...
postgresql-repmgr 18:51:11.27 INFO ==> Initializing Repmgr...
postgresql-repmgr 18:51:11.28 INFO ==> Waiting for primary node...
postgresql-repmgr 18:51:11.30 INFO ==> Cloning data from primary node...
postgresql-repmgr 18:51:12.11 INFO ==> Initializing PostgreSQL database...
postgresql-repmgr 18:51:12.11 INFO ==> Cleaning stale /bitnami/postgresql/data/standby.signal file
postgresql-repmgr 18:51:12.12 INFO ==> Custom configuration /opt/bitnami/postgresql/conf/postgresql.conf detected
postgresql-repmgr 18:51:12.13 INFO ==> Custom configuration /opt/bitnami/postgresql/conf/pg_hba.conf detected
postgresql-repmgr 18:51:12.16 INFO ==> Deploying PostgreSQL with persisted data...
postgresql-repmgr 18:51:12.19 INFO ==> Configuring replication parameters
postgresql-repmgr 18:51:12.23 INFO ==> Configuring fsync
postgresql-repmgr 18:51:12.25 INFO ==> Setting up streaming replication slave...
postgresql-repmgr 18:51:12.28 INFO ==> Starting PostgreSQL in background...
postgresql-repmgr 18:51:12.52 INFO ==> Unregistering standby node...
postgresql-repmgr 18:51:12.59 INFO ==> Registering Standby node...
postgresql-repmgr 18:51:12.64 INFO ==> Running standby follow...
postgresql-repmgr 18:51:12.71 INFO ==> Stopping PostgreSQL...
waiting for server to shut down.... done
server stopped
while normal logs continues with several restarts. The logs were confusing because no error is thrown.
Thanks to the first comment, I found that the postgres logs (which I used volumes to access later) said:
2022-10-17 12:37:51.070 GMT [171] LOG: pgaudit extension initialized
2022-10-17 12:37:51.070 GMT [171] LOG: starting PostgreSQL 12.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2022-10-17 12:37:51.072 GMT [171] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-10-17 12:37:51.072 GMT [171] LOG: listening on IPv6 address "::", port 5432
2022-10-17 12:37:51.074 GMT [171] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-10-17 12:37:51.106 GMT [171] LOG: redirecting log output to logging collector process
2022-10-17 12:37:51.106 GMT [171] HINT: Future log output will appear in directory "/opt/bitnami/postgresql/logs".
2022-10-17 12:37:51.119 GMT [173] LOG: database system was interrupted; last known up at 2022-10-17 12:37:49 GMT
2022-10-17 12:37:51.242 GMT [173] LOG: entering standby mode
2022-10-17 12:37:51.252 GMT [173] LOG: redo starts at 0/E000028
2022-10-17 12:37:51.266 GMT [173] LOG: consistent recovery state reached at 0/E000100
2022-10-17 12:37:51.266 GMT [171] LOG: database system is ready to accept read only connections
2022-10-17 12:37:51.274 GMT [177] LOG: started streaming WAL from primary at 0/F000000 on timeline 1
2022-10-17 12:37:51.579 GMT [171] LOG: received fast shutdown request
2022-10-17 12:37:51.580 GMT [171] LOG: aborting any active transactions
2022-10-17 12:37:51.580 GMT [177] FATAL: terminating walreceiver process due to administrator command
2022-10-17 12:37:51.581 GMT [174] LOG: shutting down
2022-10-17 12:37:51.601 GMT [171] LOG: database system is shut down
Can someone please tell me where I did wrong? Much appreciated!
Additional information on reproducingļ¼š
the command used for the primary node instance:
docker run --detach --name pg-0 --network my-network --env REPMGR_PARTNER_NODES=pg-0,pg-1 --env REPMGR_NODE_NAME=pg-0 --env REPMGR_NODE_NETWORK_NAME=pg-0 --env REPMGR_PRIMARY_HOST=pg-0 --env REPMGR_PASSWORD=repmgrpass --env POSTGRESQL_POSTGRES_PASSWORD=adminpassword --env POSTGRESQL_USERNAME=customuser --env POSTGRESQL_PASSWORD=custompassword --env POSTGRESQL_DATABASE=customdatabase --env POSTGRESQL_SHARED_PRELOAD_LIBRARIES=repmgr,pgaudit,timescaledb -p 5420:5432 -v /etc/localtime:/etc/localtime:ro my/pg-repmgr-12-tsdb:12.4.0-debian-10-r90
the command used for the standby node instance:
docker run --name pg-1 --network my-network --env REPMGR_PARTNER_NODES=pg-0,pg-1 --env REPMGR_NODE_NAME=pg-1 --env REPMGR_NODE_NETWORK_NAME=pg-1 --env REPMGR_PRIMARY_HOST=pg-0 --env REPMGR_PASSWORD=repmgrpass --env POSTGRESQL_POSTGRES_PASSWORD=adminpassword --env POSTGRESQL_USERNAME=customuser --env POSTGRESQL_PASSWORD=custompassword --env POSTGRESQL_DATABASE=customdatabase --env POSTGRESQL_SHARED_PRELOAD_LIBRARIES=repmgr,pgaudit,timescaledb -v /etc/localtime:/etc/localtime:ro -p 5421:5432 my/pg-repmgr-12-tsdb:12.4.0-debian-10-r90
Sometimes the best way through is just to find another...
I changed the dockerfile to
FROM bitnami/postgresql-repmgr:13.6.0-debian-10-r90
USER root
RUN apt-get update \
&& apt-get -y install \
gcc cmake git clang-format clang-tidy openssl libssl-dev \
&& git clone https://github.com/timescale/timescaledb.git
RUN cd timescaledb \
&& git checkout 2.8.0 \
&& ./bootstrap -DREGRESS_CHECKS=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
&& cd build \
&& make \
&& make install
RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen
USER 1001
and the problem is solved.
I even have no clue whether the version of base image or the version of timescaledb did the magic, but anyhow my problem is solved. Hope any one who encountered the same issue later can benefit from my struggle. >3<

Error when run bitnami postgres container

it's my first time with docker. I have created a docker container from a bitnami image with this Dockerfile:
FROM bitnami/postgresql:14.1.0
MAINTAINER <whatever>
ADD --chown=1001:1001 main /bitnami/postgresql/data
where main is a copy of my postgresql database /var/lib/postgresql/data
When I try to run the container in this way:
docker run -d --name database -p 5432:5432 -e ALLOW_EMPTY_PASSWORD=yes mypostgres
I get the following error, does anyone know what it is and how to fix it.
postgresql 15:39:28.09
postgresql 15:39:28.09 Welcome to the Bitnami postgresql container
postgresql 15:39:28.09 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
postgresql 15:39:28.09 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
postgresql 15:39:28.09
postgresql 15:39:28.12 INFO ==> ** Starting PostgreSQL setup **
postgresql 15:39:28.16 INFO ==> Validating settings in POSTGRESQL_* env vars..
postgresql 15:39:28.17 WARN ==> You set the environment variable ALLOW_EMPTY_PASSWORD=yes. For safety reasons, do not use this flag in a production environment.
postgresql 15:39:28.18 INFO ==> Loading custom pre-init scripts...
postgresql 15:39:28.18 INFO ==> Initializing PostgreSQL database...
postgresql 15:39:28.21 INFO ==> pg_hba.conf file not detected. Generating it...
postgresql 15:39:28.22 INFO ==> Generating local authentication configuration
postgresql 15:39:28.23 INFO ==> Deploying PostgreSQL with persisted data...
postgresql 15:39:28.25 INFO ==> Configuring replication parameters
postgresql 15:39:28.30 INFO ==> Configuring fsync
postgresql 15:39:28.34 INFO ==> Loading custom scripts...
postgresql 15:39:28.34 INFO ==> Enabling remote connections
postgresql 15:39:28.37 INFO ==> ** PostgreSQL setup finished! **
postgresql 15:39:28.41 INFO ==> ** Starting PostgreSQL **
2021-12-14 15:39:28.454 GMT [1] LOG: pgaudit extension initialized
2021-12-14 15:39:28.462 GMT [1] FATAL: could not open directory "pg_notify": No such file or directory
2021-12-14 15:39:28.463 GMT [1] LOG: database system is shut down

Failed to start PostgreSQL Cluster 10-main when booting

when I try to boot Ubuntu, it never finishes the boot process because it appears the message "Failed to start PostgreSQL Cluster 10-main." I also get the same message with 9.5-main. But lets focus on 10.
When I execute:
systemctl status postgresql#10-main.service
I get the following message:
postgresql#10-main.service - PostgreSQL Cluster 10-main
Loaded: loaded (/lib/systemd/system/postgresql#.service; indirect; vendor preset: enabled)
Active: failed (Result: protocol) since Wed 2020-02-19 17:57:22 CET; 30 min ago
Process: 1602 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 10-main start (code_exited, status=1/FAILURE)
PC_info systemd[1]: Starting PostgreSQL Cluster 10-main...
PC_info postgresql#10-main[1602]: Error: /usr/lib/postgresql/10/bin/pg_ctl /usr/lib/postgresql/10/bin/pg_ctl start -D /var/lib/postgresql/10/main -l /var/log/postgresql/postgresql-19-main.log -s -o -c config_file="/etc/postgresql/10/main/postgresql.conf" exit with status 1:
PC_info systemd[1]: postgresql#10-main.service: Can't open PID file /var/run/postgresql/10-main.pid (yet?) after start: No such file or directory
PC_info systemd[1]: postgresql#10-main.service: Failed with result 'protocol'.
PC_info systemd[1]: Failed to start PostgreSQL Cluster 10-main.
PC_info is information about my computer (user, date..) not relevant
I got this error from one day to an other without touching anything related to Database Servers.
I tried to fix it by my self but nothing worked
Writing the command
service postgresql#10-main start
I get
Job for postgresql#10-main.service failed because the service did not take the steps required by its unit configuration
See "systemctl status postgresql#10-main.service" and "journalctl -xe" for details.
Running this two command I get the message from the beginning.
Anyone has an idea of what is happening? How I can fix it?
I had same issue, I followed below steps,
Error status :
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
10 main 5432 down postgres /var/lib/postgresql/10/main
/var/log/postgresql/postgresql-10-main.log
Applied Solution :
sudo chmod 700 -R /var/lib/postgresql/10/main
sudo -i -u postgres
postgres#abc:~$ /usr/lib/postgresql/10/bin/pg_ctl restart -D /var/lib/postgresql/10/main
After Solution status :
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
10 main 5432 online postgres /var/lib/postgresql/10/main
/var/log/postgresql/postgresql-10-main.log
as mentioned by #gruentee in comment above,
/usr/lib/postgresql/10/bin/pg_ctl restart -D /var/lib/postgresql/10/main -l /var/log/postgresql/postgresql-10-main.log -s -o '-c config_file="/etc/postgresql/10/main/postgresql.conf"'
started the postgresSql DB. Dont forget to
sudo -i -u postgres
before issuing above command
I was facing the same challenge, I try a lot of methods but none work for me till I try these commands below
sudo apt-get -y install postgresql
sudo systemctl start postgresql#15-main.service
pg_lsclusters
then everything started working fine, but please the version of postgresql i'm using is 15 that's you are seeing 15 in the second command so in your case you substitute it with the version you are using

postgresql: errors install and run postgresql-9.5

I installed two postgresql(s), 9.5 should use port 5433, 9.3.4 should use port 5432:
me#camb:/usr/lib/postgresql/9.5/bin$ ls -al psql
-rwxr-xr-x 1 root root 564464 Jan 7 14:54 psql
me#camb:/opt/pkgs/postgresql-9.3.4/bin$ ls -al psql
-rwxr-xr-x 1 root root 405960 Aug 5 18:52 psql
me#camb:/opt/pkgs/postgresql-9.3.4/bin$ cat /etc/group
postgres:x:200:
me#camb:/opt/pkgs/postgresql-9.3.4/bin$ groups postgres
postgres : postgres ssl-cert
I wrote a script to install postgresql-9.5 and migrate from 9.3.4 to 9.5
Problem 0: postgresql-9.5 can not start sucessfully and why status is online
Output during install:
* Starting PostgreSQL 9.5 database server
* The PostgreSQL server failed to start. Please check the log output:
2016-01-19 19:41:49 UTC [16523-1] LOG: database system was shut down at 2016-01-19 19:41:48 UTC
2016-01-19 19:41:49 UTC [16523-2] LOG: MultiXact member wraparound protections are now enabled
2016-01-19 19:41:49 UTC [16522-1] LOG: database system is ready to accept connections
2016-01-19 19:41:49 UTC [16527-1] LOG: autovacuum launcher started
2016-01-19 19:41:49 UTC [16529-1] [unknown]#[unknown] LOG: incomplete startup packet
...fail!
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing postgresql-9.5 (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of postgresql:
postgresql depends on postgresql-9.5; however:
Package postgresql-9.5 is not configured yet.
dpkg: error processing postgresql (--configure):
dependency problems - leaving unconfigured
Processing triggers for libc-bin ...
No apport report written because the error message indicates its a followup error from a previous failure.
ldconfig deferred processing now taking place
Errors were encountered while processing:
postgresql-9.5
postgresql
E: Sub-process /usr/bin/dpkg returned an error code (1)
Error while installing Postgresql-9.5:1
Then I did some tests:
me#camb:/usr/lib/postgresql/9.5/bin$ sudo service postgresql start
* Starting PostgreSQL 9.5 database server [ OK ]
me#camb:/usr/lib/postgresql/9.5/bin$ sudo service postgresql status
9.5/main (port 5433): online
What do the above errors?
By the way, another error is:
ERROR: role "postgres" already exists
Problem 1: Why I cannot use /usr/lib/postgresql/9.5/bin/psql to loginto the database, but I can do this by /opt/pkgs/postgresql-9.3.4/bin/psql
me#camb:/usr/lib/postgresql/9.5/bin$ sudo -u postgres /opt/pkgs/postgresql-9.3.4/bin/psql -p 5433 reporting_central postgres
psql (9.3.4, server 9.5.0)
WARNING: psql major version 9.3, server major version 9.5.
Some psql features might not work.
Type "help" for help.
reporting_central=# \q
me#camb:/usr/lib/postgresql/9.5/bin$ sudo -u postgres /opt/pkgs/postgresql-9.3.4/bin/psql -p 5432 reporting_central postgres
psql (9.3.4)
Type "help" for help.
reporting_central=# \q
me#camb:/usr/lib/postgresql/9.5/bin$ sudo -u postgres /usr/lib/postgresql/9.5/bin/psql -p 5433 reporting_central postgres
/usr/lib/postgresql/9.5/bin/psql: symbol lookup error: /usr/lib/postgresql/9.5/bin/psql: undefined symbol: PQsslInUse
me#camb:/usr/lib/postgresql/9.5/bin$ sudo -u postgres /usr/lib/postgresql/9.5/bin/psql -p 5432 reporting_central postgres
/usr/lib/postgresql/9.5/bin/psql: symbol lookup error: /usr/lib/postgresql/9.5/bin/psql: undefined symbol: PQsslInUse
The error is "undefined symbol: PQsslInUse". what does this mean? Why I cannot use /usr/lib/postgresql/9.5/bin/psql to loginto the database, but I can do this by /opt/pkgs/postgresql-9.3.4/bin/psql?
Thanks
By the way, I run the following to do migration:
sudo -u postgres /opt/pkgs/postgresql-9.3.4/bin/pg_dumpall -p 5432 | sudo -u postgres /opt/pkgs/postgresql-9.3.4/bin/psql -p 5433
Thanks
You have to use the same libpq library as the one used in psql 9.5.
You should do the following:
export LD_LIBRARY_PATH=/usr/lib/postgresql/9.5/lib:$LD_LIBRARY_PATH
sudo /sbin/ldconfig /usr/lib/postgresql/9.5/lib
You mess up with different versions of postgresql.
To start/use 9.5, you must use the appropriate binaries: initdb, pg_ctl and psql (for example):
mkdir /usr/lib/postgresql/9.5/data
/usr/lib/postgresql/9.5/bin/initdb -D ../data/
/usr/lib/postgresql/9.5/bin/pg_ctl -D ../data/ -l logfile start
/usr/lib/postgresql/9.5/bin/psql -p 5432 -d template1
More info: https://www.postgresql.org/docs/devel/static/install-post.html
and PQsslInUse issue: http://postgresql.nabble.com/psql-error-on-postgresql-9-0-psql-symbol-lookup-error-psql-undefined-symbol-PQconnectdbParams-td5104930.html
The error is "undefined symbol: PQsslInUse"
I just ran into this problem myself. I discovered that the reason was because I compiled Postgres 9.5 from scratch into a particular directory and then decided that I wanted it elsewhere and moved the install to a new directory. Down the line when I went to restore my database with psql, I got the above error. I corrected the problem by deleting my installation directory, changing the PREFIX to the correct location, recompiling and reinstalling Postgres. psql worked fine after this.
I had the same problem
psql: symbol lookup error: psql: undefined symbol: PQsetErrorContextVisibility
And the solution is :
export LD_LIBRARY_PATH=$PGXZ_HOME/lib:${LD_LIBRARY_PATH}
I had a similar issue and finally found a solution:
My user did not have permission for the postgres installation.
What worked for me was to switch to the postgres user:
sudo su - postgres
psql
and then it worked no issues.

gerrit not starting with postgres

Following these instructions:
https://gerrit-documentation.storage.googleapis.com/Documentation/2.11.4/install.html
Installed postgres 9.3:
sudo -i -u postgres
postgres#ubuntu:~$ psql
psql (9.3.10)
Type "help" for help.
postgres=#
The gerrit2 user cannot access psql, even though I created the user and database
postgres#ubuntu:~$ createuser --username=postgres -RDIElPS gerrit2
postgres#ubuntu:~$ createdb --username=postgres -E UTF-8 -O gerrit2 reviewdb
^d
gerrit2#ubuntu:~$ psql
psql: FATAL: database "gerrit2" does not exist
Installed gerrit 2.11.4:
gerrit2#ubuntu:~$ java -jar gerrit-2.11.4.war init -d .
See gerrit.conf result of install:
[gerrit]
basePath = .
canonicalWebUrl = http://ubuntu:8080/
[database]
type = postgresql
hostname = localhost
database = reviewdb
username = gerrit2
[index]
type = LUCENE
[auth]
type = OPENID
[sendemail]
smtpServer = localhost
smtpUser = lmougen5
[container]
user = gerrit2
javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre
[sshd]
listenAddress = *:22
[httpd]
listenUrl = http://*:8080/
[cache]
directory = cache
gerrit init didn't bring up the browser as per the instructions, so I attempted a reindex. Note errors in output:
gerrit2#ubuntu:~$ java -jar gerrit-2.11.4.war reindex
[2015-11-19 16:42:24,861] INFO com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaulting core.streamFileThreshold to 119m
[2015-11-19 16:42:25,542] INFO com.google.gerrit.server.cache.h2.H2CacheFactory : Enabling disk cache /home/gerrit2/cache
Reindexing changes: done
Reindexed 0 changes in 0.0s (0.0/s)
[2015-11-19 16:42:26,525] WARN com.google.gerrit.server.cache.h2.H2CacheImpl : Cannot build BloomFilter for jdbc:h2:file:/home/gerrit2/cache/diff_intraline: Error opening database: "Sleep interrupted" [8000-174]
[2015-11-19 16:42:26,526] INFO com.google.gerrit.server.cache.h2.H2CacheFactory : Finishing 4 disk cache updates
Then a restart, probably need to address errors first. Along with gerrit2 user's access to psql reviewdb:
gerrit2#ubuntu:~$ ~/bin/gerrit.sh restart
Restart failed, here's ~/logs/error_log:
[2015-11-20 08:12:30,627] INFO com.google.gerrit.server.cache.h2.H2CacheFactory : Enabling disk cache /home/gerrit2/cache
[2015-11-20 08:12:31,970] INFO com.google.gerrit.server.config.ScheduleConfig : gc schedule parameter "gc.interval" is not configured
[2015-11-20 08:12:33,640] WARN com.google.gerrit.httpd.GitWebConfig : gitweb not installed (no /usr/lib/cgi-bin/gitweb.cgi found)
[2015-11-20 08:12:34,415] INFO org.eclipse.jetty.util.log : Logging initialized #8505ms
[2015-11-20 08:12:35,115] INFO com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaulting core.streamFileThreshold to 119m
[2015-11-20 08:12:35,204] INFO com.google.gerrit.server.plugins.PluginLoader : Loading plugins from /home/gerrit2/plugins
[2015-11-20 08:12:35,363] INFO com.google.gerrit.server.plugins.PluginLoader : Loaded plugin commit-message-length-validator, version v2.11.4
[2015-11-20 08:12:35,479] INFO com.google.gerrit.server.plugins.PluginLoader : Loaded plugin download-commands, version v2.11.4
[2015-11-20 08:12:35,603] WARN com.googlesource.gerrit.plugins.replication.ReplicationFileBasedConfig : Config file /home/gerrit2/etc/replication.configdoes not exist; not replicating
[2015-11-20 08:12:35,617] INFO com.google.gerrit.server.plugins.PluginLoader : Loaded plugin replication, version v2.11.4
[2015-11-20 08:12:35,726] INFO com.google.gerrit.server.plugins.PluginLoader : Loaded plugin reviewnotes, version v2.11.4
[2015-11-20 08:12:35,787] INFO com.google.gerrit.server.plugins.PluginLoader : Loaded plugin singleusergroup, version v2.11.4
[2015-11-20 08:12:36,290] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
java.lang.IllegalStateException: Cannot bind to *
at com.google.gerrit.sshd.SshDaemon.start(SshDaemon.java:319)
at com.google.gerrit.lifecycle.LifecycleManager.start(LifecycleManager.java:74)
at com.google.gerrit.pgm.Daemon.start(Daemon.java:293)
at com.google.gerrit.pgm.Daemon.run(Daemon.java:205)
at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:166)
at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:93)
at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:50)
at Main.main(Main.java:25)
Caused by: java.io.IOException: Error while binding on 0.0.0.0/0.0.0.0:22
original message : Permission denied
at org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:238)
at org.apache.mina.transport.socket.nio.NioSocketAcceptor.open(NioSocketAcceptor.java:51)
at org.apache.mina.core.polling.AbstractPollingIoAcceptor.registerHandles(AbstractPollingIoAcceptor.java:582)
at org.apache.mina.core.polling.AbstractPollingIoAcceptor.access$400(AbstractPollingIoAcceptor.java:70)
at org.apache.mina.core.polling.AbstractPollingIoAcceptor$Acceptor.run(AbstractPollingIoAcceptor.java:456)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Gerrit runs its own ssh daemon instance and thus must be given its own port separate than any other sshd instances.
The init failure went away once given a unique port, and then the gerrit web site was accessible.
Bad:
[sshd]
listenAddress = *:22
Good:
[sshd]
listenAddress = *:29418