invalid length of startup packet docker postgressql - postgresql

PostgreSQL init process complete; ready for start up.
2022-05-16 19:28:51.674 UTC [1] LOG: starting PostgreSQL 14.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.3.1_git20211027) 10.3.1 20211027, 64-bit
2022-05-16 19:28:51.674 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-05-16 19:28:51.674 UTC [1] LOG: listening on IPv6 address "::", port 5432
2022-05-16 19:28:51.677 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-05-16 19:28:51.681 UTC [51] LOG: database system was shut down at 2022-05-16 19:28:51 UTC
2022-05-16 19:28:51.684 UTC [1] LOG: database system is ready to accept connections
2022-05-16 19:29:07.610 UTC [59] LOG: invalid length of startup packet
2022-05-16 19:29:07.611 UTC [58] LOG: invalid length of startup packet
2022-05-16 19:29:07.612 UTC [60] LOG: invalid length of startup packet
2022-05-16 19:29:08.647 UTC [62] LOG: invalid length of startup packet
2022-05-16 19:29:08.650 UTC [61] LOG: invalid length of startup packet
2022-05-16 19:29:08.652 UTC [63] LOG: invalid length of startup packet
Any help would be appreciated I couldn't figure out
Docker composer file
version: '3.9'
services:
postgres:
image: postgres:14-alpine
ports:
- 5432:5432
volumes:
- ~/apps/postgres:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=S3cret
- POSTGRES_USER=citizix_user
- POSTGRES_DB=citizix_db
Using ubuntu 20.4

Something, probably a monitoring system, is establishing TCP connections to the database server, then closing them without sending a correct PostgreSQL connection packet.
You can include %h in your log_line_prefix to see the client address of these connections, which may help identify the culprit.
The solution is to get the monitoring system to establish a database connection rather than only a TCP connection. Not only will that get rid of the message, but it will make the test much more useful.

Related

pg_ctl: could not start server

I am trying to execute PostgreSQL unsuccessfully on Ubuntu
# /etc/init.d/postgresql start
* Starting PostgreSQL 11 database server * Removed stale pid file.
Error: /usr/lib/postgresql/11/bin/pg_ctl /usr/lib/postgresql/11/bin/pg_ctl start -D /export/postgresql/11/main/ -l /var/log/postgresql/postgresql-11-main.log -s -o exited with status 1:
2022-11-14 14:00:57.126 UTC [29005] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-11-14 14:00:57.126 UTC [29005] LOG: listening on IPv6 address "::", port 5432
2022-11-14 14:00:57.182 UTC [29005] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
pg_ctl: could not start server
Examine the log output.
[fail]
There is no much information to tell me what is wrong. How can investigate this issue?

Unable to connect to docker container which includes a postgres instance

I have a docker instance and I have changed the file =:
"/var/lib/postgreqsql/data/pg_hba.conf"
And it now has errors.
It appears that this is preventing me actually connecting to the docker instance.
docker logs --tail 20 postgres
2022-08-04 00:30:26.392 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-08-04 00:30:26.392 UTC [1] LOG: listening on IPv6 address "::", port 5432
2022-08-04 00:30:26.417 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-08-04 00:30:26.451 UTC [1] LOG: end-of-line before authentication method
2022-08-04 00:30:26.451 UTC [1] CONTEXT: line 87 of configuration file "/var/lib/postgreqsql/data/pg_hba.conf"
2022-08-04 00:30:26.451 UTC [1] FATAL: could not load pg_hba.conf
2022-08-04 00:30:26.453 UTC [1] LOG: database system is shut down
When I try and connect I get a consistent message as follows:
root#VM01:~/vm01-docker# docker exec -u root -it postgres bash
Error response from daemon: Container 4545dcba980215c is restarting, wait until the container is running
root#VM01:~/vm01-docker#
Stopping and starting as follows:
docker-compose stop postgres
docker-compose start postgres
Has no impact the issue remains.
What I need to do is be able to connect again to the instance and edit the file pg_hba.conf again to correct the fault but I am not sure how I can. (I am a docker newb.)

Could not bind wireguard address when starting postgresql

I'm running wg-quick.service on system startup to establish a VPN tunnel:
root#db ~ # cat /usr/lib/systemd/system/wg-quick#.service
[Unit]
Description=WireGuard via wg-quick(8) for %I
After=network-online.target nss-lookup.target
Wants=network-online.target nss-lookup.target
PartOf=wg-quick.target
Documentation=man:wg-quick(8)
Documentation=man:wg(8)
Documentation=https://www.wireguard.com/
Documentation=https://www.wireguard.com/quickstart/
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/wg-quick up %i
ExecStop=/usr/bin/wg-quick down %i
Environment=WG_ENDPOINT_RESOLUTION_RETRIES=infinity
[Install]
WantedBy=multi-user.target
I want postgresql to listen on the wireguard address - 10.100.0.107:
root#db ~ # cat /etc/postgresql/13/main/conf.d/db1.conf | grep listen
listen_addresses = '127.0.0.1,10.100.0.107' # what IP address(es) to listen on;
After reboot I got following errors in my postgresql log:
2021-06-23 19:44:26.389 UTC [831] LOG: starting PostgreSQL 13.3 (Ubuntu 13.3-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
2021-06-23 19:44:26.389 UTC [831] LOG: listening on IPv4 address "127.0.0.1", port 5432
2021-06-23 19:44:26.395 UTC [831] LOG: could not bind IPv4 address "10.100.0.107": Cannot assign requested address
2021-06-23 19:44:26.395 UTC [831] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2021-06-23 19:44:26.395 UTC [831] WARNING: could not create listen socket for "10.100.0.107"
2021-06-23 19:44:26.395 UTC [831] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-06-23 19:44:26.411 UTC [880] LOG: database system was shut down at 2021-06-23 19:43:14 UTC
2021-06-23 19:44:26.422 UTC [831] LOG: database system is ready to accept connections
Sadly, postgresql does not accept connections at 10.100.0.107.
Restart of postgresql after server reboot helps.
Also set listen_addresses='*' helps too.
But I would like to accept connections to only the specified addresses: 127.0.0.1, 10.100.0.107. How can I start a postgresql service after successfully initializing the wg-quick service?
Thanks!

How to use SCRAM-SHA-256 based authentication for user with TLS config in POSTGRESQL server?

I have created a PostgreSQL 13.1 cluster with 1` where I have 2 standby and 1 primary.
Here I have used scram-sha-256as authentication mode for client where my cluster is config with TLS.
When I started my PostgreSQL server, I got a continuous fatal log.
the log is:
UTC [181] FATAL: expected SASL response, got message type 88
postgresql.conf
wal_level = replica
max_wal_senders = 90
wal_keep_size = 64
wal_log_hints = on
hot_standby = on
password_encryption = scram-sha-256
recovery_target_timeline = 'latest'
primary_conninfo = 'application_name=<application_name> host=<host_name> password=<Postgres_password sslmode=verify-full sslrootcert=<path_to_ca_cert>/ca.crt'
promote_trigger_file = '/run_scripts/tmp/pg-failover-trigger'
...
<some other basic config>
...
pg_hba.conf
#TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 scram-sha-256
local replication all scram-sha-256
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
host all all 0.0.0.0/0 scram-sha-256
host replication postgres 0.0.0.0/0 scram-sha-256
host all all ::/0 scram-sha-256
host replication postgres ::/0 scram-sha-256
Is it possible to add scram-sha-256 for tls config cluster? If yes, then how can I do it?
Here is how I have tried to connect as a client.
$ export PGPASSWORD=<POSTGRES_PASSWORD>
$ export PGUSER=<POSTGRES_USER>
$ psql -w -h <hostname>
psql (13.1)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
postgres=#
I don't see any error from my client site but get continuous fatal log.
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/pv/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
sh: locale: not found
2021-03-03 07:43:56.823 UTC [35] WARNING: no usable system locales were found
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/pv/data -l logfile start
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
waiting for server to start....2021-03-03 07:44:03.835 GMT [42] LOG: skipping missing configuration file "/etc/config/user.conf"
2021-03-03 07:44:03.836 GMT [42] LOG: skipping missing configuration file "/etc/config/user.conf"
2021-03-03 07:44:03.996 UTC [42] LOG: starting PostgreSQL 13.1 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, 64-bit
2021-03-03 07:44:03.996 UTC [42] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-03-03 07:44:03.996 UTC [42] LOG: listening on IPv6 address "::", port 5432
2021-03-03 07:44:04.073 UTC [42] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-03-03 07:44:04.187 UTC [43] LOG: database system was shut down at 2021-03-03 07:43:59 UTC
2021-03-03 07:44:04.237 UTC [44] FATAL: the database system is starting up
2021-03-03 07:44:04.281 UTC [42] LOG: database system is ready to accept connections
done
server started
ALTER ROLE
/run_scripts/role/start.sh: ignoring /var/initdb/*
waiting for server to shut down...2021-03-03 07:44:04.387 UTC [42] LOG: received fast shutdown request
.2021-03-03 07:44:04.478 UTC [42] LOG: aborting any active transactions
2021-03-03 07:44:04.480 UTC [42] LOG: background worker "logical replication launcher" (PID 51) exited with exit code 1
2021-03-03 07:44:04.482 UTC [45] LOG: shutting down
2021-03-03 07:44:05.169 UTC [56] FATAL: the database system is shutting down
.2021-03-03 07:44:05.702 UTC [57] FATAL: the database system is shutting down
2021-03-03 07:44:05.806 UTC [58] FATAL: the database system is shutting down
2021-03-03 07:44:06.217 UTC [59] FATAL: the database system is shutting down
..2021-03-03 07:44:07.648 UTC [60] FATAL: the database system is shutting down
2021-03-03 07:44:07.853 UTC [61] FATAL: the database system is shutting down
2021-03-03 07:44:08.163 UTC [42] LOG: database system is shut down
done
server stopped
2021-03-03 07:44:08.208 GMT [25] LOG: skipping missing configuration file "/etc/config/user.conf"
2021-03-03 07:44:08.208 GMT [25] LOG: skipping missing configuration file "/etc/config/user.conf"
2021-03-03 07:44:08.487 UTC [25] LOG: starting PostgreSQL 13.1 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, 64-bit
2021-03-03 07:44:08.487 UTC [25] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-03-03 07:44:08.487 UTC [25] LOG: listening on IPv6 address "::", port 5432
2021-03-03 07:44:08.688 UTC [25] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-03-03 07:44:08.895 UTC [67] LOG: database system was shut down at 2021-03-03 07:44:07 UTC
2021-03-03 07:44:08.905 UTC [68] FATAL: the database system is starting up
2021-03-03 07:44:08.945 UTC [69] FATAL: the database system is starting up
2021-03-03 07:44:08.946 UTC [70] FATAL: the database system is starting up
2021-03-03 07:44:08.991 UTC [25] LOG: database system is ready to accept connections
2021-03-03 07:44:15.990 UTC [94] FATAL: expected SASL response, got message type 88
2021-03-03 07:44:16.011 UTC [95] FATAL: expected SASL response, got message type 88
2021-03-03 07:44:30.197 UTC [108] FATAL: expected SASL response, got message type 88
2021-03-03 07:44:31.324 UTC [110] FATAL: expected SASL response, got message type 88
2021-03-03 07:44:57.571 UTC [114] FATAL: expected SASL response, got message type 88
2021-03-03 07:44:57.729 UTC [115] FATAL: expected SASL response, got message type 88
2021-03-03 07:45:07.982 UTC [127] FATAL: expected SASL response, got message type 88
2021-03-03 07:45:08.020 UTC [128] FATAL: expected SASL response, got message type 88
2021-03-03 07:45:18.135 UTC [140] FATAL: expected SASL response, got message type 88
2021-03-03 07:45:18.173 UTC [141] FATAL: expected SASL response, got message type 88
The problem was with the go-client i was trying to use to connect my server. The problem was solved when i tried https://github.com/lib/pq client instead of https://github.com/go-pg/pg.

Postgres:10 in docker swarm cluster. Database system is shut down

I use postgres:10 (https://hub.docker.com/_/postgres/) image for DB.
It is deployed in docker swarm cluster.
After running DB replica I got database system is shut down in DB's log.
2018-05-11 10:26:53.073 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432,
2018-05-11 10:26:53.073 UTC [1] LOG: listening on IPv6 address "::", port 5432,
2018-05-11 10:26:53.077 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432",
2018-05-11 10:26:53.092 UTC [20] LOG: database system was shut down at 2018-05-11 10:26:20 UTC,
2018-05-11 10:26:53.100 UTC [1] LOG: database system is ready to accept connections,
The files belonging to this database system will be owned by user "postgres".,
This user must also own the server process.,
,
The database cluster will be initialized with locale "en_US.utf8".,
The default database encoding has accordingly been set to "UTF8".,
The default text search configuration will be set to "english".,
,
Data page checksums are disabled.,
,
fixing permissions on existing directory /var/lib/postgresql/data ... ok,
creating subdirectories ... ok,
selecting default max_connections ... 100,
selecting default shared_buffers ... 128MB,
selecting dynamic shared memory implementation ... posix,
creating configuration files ... ok,
running bootstrap script ... ok,
performing post-bootstrap initialization ... ok,
,
WARNING: enabling "trust" authentication for local connections,
You can change this by editing pg_hba.conf or using the option -A, or,
--auth-local and --auth-host, the next time you run initdb.,
syncing data to disk ... ok,
,
Success. You can now start the database server using:,
,
pg_ctl -D /var/lib/postgresql/data -l logfile start,
,
waiting for server to start....2018-05-11 09:39:21.129 UTC [37] LOG: listening on IPv4 address "127.0.0.1", port 5432,
2018-05-11 09:39:21.130 UTC [37] LOG: could not bind IPv6 address "::1": Cannot assign requested address,
2018-05-11 09:39:21.130 UTC [37] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.,
2018-05-11 09:39:21.133 UTC [37] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432",
2018-05-11 09:39:21.147 UTC [38] LOG: database system was shut down at 2018-05-11 09:39:20 UTC,
2018-05-11 09:39:21.152 UTC [37] LOG: database system is ready to accept connections,
done,
server started,
CREATE DATABASE,
,
CREATE ROLE,
,
,
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*,
,
2018-05-11 09:39:21.595 UTC [37] LOG: received fast shutdown request,
waiting for server to shut down....2018-05-11 09:39:21.596 UTC [37] LOG: aborting any active transactions,
2018-05-11 09:39:21.598 UTC [37] LOG: worker process: logical replication launcher (PID 44) exited with exit code 1,
2018-05-11 09:39:21.599 UTC [39] LOG: shutting down,
2018-05-11 09:39:21.613 UTC [37] LOG: database system is shut down,
done,
server stopped,
,
PostgreSQL init process complete; ready for start up.,
,
2018-05-11 09:39:21.706 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432,
2018-05-11 09:39:21.706 UTC [1] LOG: listening on IPv6 address "::", port 5432,
2018-05-11 09:39:21.709 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432",
2018-05-11 09:39:21.724 UTC [64] LOG: database system was shut down at 2018-05-11 09:39:21 UTC,
2018-05-11 09:39:21.729 UTC [1] LOG: database system is ready to accept connections,
2018-05-11 10:26:20.444 UTC [1] LOG: received smart shutdown request,
2018-05-11 10:26:20.449 UTC [1] LOG: worker process: logical replication launcher (PID 70) exited with exit code 1,
2018-05-11 10:26:20.449 UTC [65] LOG: shutting down,
2018-05-11 10:26:20.460 UTC [1] LOG: database system is shut down,
Image :
FROM postgres:10
COPY healthcheck /usr/local/bin/
RUN chmod +x /usr/local/bin/healthcheck
HEALTHCHECK --interval=30s --timeout=30s --retries=3 \
CMD healthcheck
Snippet from docker-compose :
db_jackrabbit:
build: ./images/pgsql_jackrabbit
container_name: db_jackrabbit
environment:
- POSTGRES_DB=${JACK_POSTGRES_DB}
- POSTGRES_USER=${JACK_POSTGRES_USER}
- POSTGRES_PASSWORD=${JACK_POSTGRES_PASSWORD}
volumes:
- pgsql_jackrabbit_local:/var/lib/postgresql/data
ports:
- ${PORT_DB_JACKRABBIT}:5432
healthcheck:
#!/bin/bash
set -eo pipefail
host="$(hostname -i || echo '127.0.0.1')"
user="${POSTGRES_USER:-postgres}"
db="${POSTGRES_DB:-$POSTGRES_USER}"
export PGPASSWORD="${POSTGRES_PASSWORD:-}"
args=(
# force postgres to not use the local unix socket (test "external" connectibility)
--host "$host"
--username "$user"
--dbname "$db"
--quiet --no-align --tuples-only
)
if select="$(echo 'SELECT 1' | psql "${args[#]}")" && [ "$select" = '1' ]; then
exit 0
fi
exit 1
But DB still alive. It is shutdown periodically and accept connections again (
What it the problem?
Thanks in advance!
Ok, so I solved my issue. This issue helped me.
It seems like Postgres initialization process does stop the initialization process once done, and it is another process which follows up and accepts connexion.
Hence I had:
postgres:
deploy:
restart_policy:
condition: on-failure
window: 15m
and apparently docker received a end-of-process status code, so it stopped without going to the next process so never accepting connexions.
My interpretation may be incorrect, but at least if you face the issue, try removing restart_policy key to see if it fixes it.
I haven't tried to restore healthcheck yet, as it may also have undesired side effects.