PostgreSQL won't start after Windows update restarts - service

I have a Windows 2012R2 server with PostgreSQL 9.3.4 x64 installed as a service. It seems like everytime the server perform a Windows update and finally restart, the PostgreSQL service fail to start again. Here's the PostgreSQL log before the restart:
LOG: received fast shutdown request
LOG: aborting any active transactions
FATAL: terminating connection due to administrator command
FATAL: terminating connection due to administrator command
FATAL: terminating connection due to administrator command
FATAL: terminating connection due to administrator command
FATAL: terminating connection due to administrator command
FATAL: terminating connection due to administrator command
LOG: autovacuum launcher shutting down
ERROR: canceling statement due to user request
LOG: autovacuum launcher shutting down
After the restart I have several postgres.exe instances running on the server and the database folder contains a postmaster.pid which is not empty. The PostgreSQL log after restart contains the following:
FATAL: the database system is starting up
LOG: database system was interrupted; last known up at 2016-04-09 02:31:22 CEST
LOG: database system was not properly shut down; automatic recovery in progress
LOG: record with zero length at D2/9C630820
LOG: redo is not required
FATAL: the database system is starting up
FATAL: the database system is starting up
...
FATAL: the database system is starting up
Since the database is normally used for readonly purposes I guess I probably won't experience database corruption.
So far I can manually force the postgres.exe instances to shut down (though I have just one instance, which gives me Access denied when I perform an End process on it), delete the postmaster.pid file and then restart the PostgreSQL service. The service seem to start okay even though I have the rogue postgres.exe instance still running.
What could be the reason for Windows and PostgreSQL to struggle like this?

Related

pgAgent isnt running jobs

I just checked the log and it says:
2022-05-25 03:04:22.128 IST [11608] LOG: could not send data to
client: An existing connection was forcibly closed by the remote host.
I don't know what to do.

Postgres/Mac - 'service already loaded', but 'could not connect to server'

I'm running Homebrew-installed Postgres version 9.6.3 on my Mac (High Sierra, 10.13.3), and this morning I'm finding that Postgres is having some issues. It was working fine last night, then I put the computer to sleep... when I woke it up this morning and tried to run a Phoenix app, I got
[error] Postgrex.Protocol (#PID<0.306.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
Running psql returned
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
so it seemed that perhaps the server had stopped... however, running my alias pg-start, which translates to launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist returns
/usr/local/Cellar/postgresql/9.6.3/homebrew.mxcl.postgresql.plist: service already loaded
So this is confusing, because it seems that one command suggests that Postgres is not running, while the other suggests that it is.
I can't recall for sure, but I may have stopped the server before putting the computer to sleep last night, which I actually usually do not do... my pg-stop alias is launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
though I can't see why that would cause problems, it's the only thing that sticks out in my mind as something 'different' that I may have done.
I've tried restarting my machine, but the problem persists. I'm not terribly experienced with debugging this sort of issue, so any guidance or suggestions would be much appreciated.
Well, I resolved it, though I'm not sure what the exact problem was. To get some more error info, I ran
postgres -D /usr/local/var/postgres
which gave me
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 323) running in data directory "/usr/local/var/postgres"?
which I'd encountered before, so I kind of knew how to proceed...
Here are the steps I took to resolve this:
First, I ran
pg_ctl -D /usr/local/var/postgres start
which returned
pg_ctl: another server might be running; trying to start server anyway
server starting
My-MBP:~ me$ FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 1188) running in data directory "/usr/local/var/postgres"?
then I ran my alias pg-stop
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
followed by
pg_ctl -D /usr/local/var/postgres start
again. This time, it returned
server starting
My-MBP:~ me$ LOG: database system was shut down at 2018-02-07 11:10:43 EST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
and now Postgres was running correctly - psql commands, etc.
However, now my alias pg-stop wouldn't work -
/Users/me/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: Could not find specified service
I ran
pg_ctl -D /usr/local/var/postgres stop
and then my pg-stop alias was restored. So now pg-start and pg-stop are working as they should be.
I hope that this is helpful to someone in the future, but if anyone can explain what happened here, I'd really appreciated having a deeper understanding of what went wrong.

Builds with postgres service are stalling

I haven't run this particular build in a month or so, and I recently updated from drone version 0.5 to 0.7.3. I've hit an issue where a a build with a postgres service never completes. According to the logs, it should be accepting connections, but it never moves past the the step of starting up the service.
Example that will Stall out
.drone.yml
pipeline:
Run Something:
image: busybox
commands:
- echo 'hello'
services:
postgres:
image: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=pgpass
ports:
- '15432:5432'
Log Output
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
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
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....LOG: database system was shut down at 2017-08-17 00:06:37 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
done
server started
ALTER ROLE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
LOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
waiting for server to shut down....LOG: shutting down
LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
LOG: database system was shut down at 2017-08-17 00:06:38 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
Notes
Everything just stays here, and the build never completes. If I remove the ports and environment variables, I can get it to run. I did that in a sandbox that doesn't require configuration to run properly... Of course, in practice, I do need to adjust ports and passwords to make the build function properly.
I haven't changed anything but the version of drone in the last month or so. I'm stumped.
Things I've Tried
Changing removing one ENV var at a time
Different versions of postgres
Not defining the port mapping
Using detach: true rather than a service
Thank for your time!
After looking this over for a while, I couldn't locate the source of the problem. I decided to spin up an all new instance of drone that hadn't been upgraded, and reconfigure it. This appears to be working now. My only guess is that there was some kind of corruption.
At least running with docker spinning up a new instance to test was pretty easy.

Restart postgres server writes fatal error password authentication for user postgres in logfile

When i restart the postgresql server with sudo service postgresql restart everything works as expected.
But the logfile /var/log/postgresql/postgresql-9.3-main.log shows that a fatal error happened.
2016-12-09 11:50:26 CET LOG: MultiXact member wraparound protections are now enabled
2016-12-09 11:50:26 CET LOG: autovacuum launcher started
2016-12-09 11:50:26 CET LOG: database system is ready to accept connections
2016-12-09 11:50:26 CET FATAL: password authentication failed for user "postgres"
2016-12-09 11:50:26 CET DETAIL: Connection matched pg_hba.conf line xx: "local all postgres md5"
2016-12-09 11:50:27 CET FATAL: password authentication failed for user "postgres"
I did setup the postgres superuser postgres with a secure password.
I am able to login with
psql -U postgres
But the UNIX user postgres is also setup with a login shell and a password. So i locked this user by setting /usr/sbin/nologin in /etc/passwd.
I am not able to su into the UNIX postgres user anymore but with
sudo -u postgres psql postgres
it is possible to log into the database.
Restarting the server still shows the same error message.
In pg_hba.conf the method for postgres and all is set to md5.
I dont really understand what the server is complaining about, because the connection can be established and i am able to login.
Many thanks in advance!
Either set in pg_hba.conf user "postgres" as "peer" authentication or add into postgres $HOME directory file .pgpass with content localhost:*:*:postgres:password. File must have mod 600.

postgres does not know where to find the server configuration file

I had installed PostgreSQL but when I do run command postgres in windows CMD
It gives following error:
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
Even after running command
initdb postgres as maintained similar Issue
postgres -D C:\Program Files\PostgreSQL\data\
gave me following output:
2016-09-28 15:04:57 PDT LOG: could not bind IPv6 socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.
2016-09-28 15:04:57 PDT HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-09-28 15:04:57 PDT LOG: could not bind IPv4 socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.
2016-09-28 15:04:57 PDT HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-09-28 15:04:57 PDT WARNING: could not create listen socket for "*"
2016-09-28 15:04:57 PDT FATAL: could not create any TCP/IP sockets
2016-09-28 15:04:57 PDT LOG: database system is shut down
As the error says, to start a postgresql cluster you must set the path to the data folder. Probably something like:
postgres -D "C:\Program Files\PostgreSQL\data\"
but the use of pg_ctl instead postgres is recommended:
pg_ctl -D "C:\Program Files\PostgreSQL\data\" start
Don't forget to check the postgres documentation about how to start a server and how to use pg_ctl.
Usually, the postgres installlers creates a service/daemon so there is not need to launch the server by hand. So if you get an error like
Is another postmaster already running on port 5432?
It probably means that the server is already running. Try to connect to it using psql