Postgresql Logger Process - postgresql

I'm trying to determine if Postgres 9.3 still has a logger process. It isn't referenced anywhere in the "PostgreSQL 9.3.4 Documentation". And I can't find it in my cluster's process list (see below). Also, does anyone know of a good general overview the memory structures in 9.3?
postgres 21397 1 0 20:51 pts/1 00:00:00 /opt/PostgreSQL/9.3/bin/postgres
postgres 21399 21397 0 20:51 ? 00:00:00 postgres: checkpointer process
postgres 21400 21397 0 20:51 ? 00:00:00 postgres: writer process
postgres 21401 21397 0 20:51 ? 00:00:00 postgres: wal writer process
postgres 21402 21397 0 20:51 ? 00:00:00 postgres: autovacuum launcher process
postgres 21403 21397 0 20:51 ? 00:00:00 postgres: archiver process last was 0001000004000092
postgres 21404 21397 0 20:51 ? 00:00:00 postgres: stats collector process
Thanks
Jim

Postgres has a logging collector process which is controlled through a config parameter,
logging_collector.
So in your postgresql.conf file, you would make sure this is set:
logging_collector = on
The blurb on this param from the postgres doc:
This parameter enables the logging collector, which is a background
process that captures log messages sent to stderr and redirects them
into log files. This approach is often more useful than logging to
syslog, since some types of messages might not appear in syslog
output. (One common example is dynamic-linker failure messages;
another is error messages produced by scripts such as
archive_command.) This parameter can only be set at server start.
It will show up in the process list with the following description:
postgres: logger process
For more info: http://www.postgresql.org/docs/current/static/runtime-config-logging.html
Regarding the memory structures, I'm not sure offhand, but would recommend you post that as a separate question.

Related

How to stop postgres stats collector properly?

I tried to profile plpgsql functions.
And I use pg_stat_statements to do that.
I can do profile, but after that I can not restart postgresql.
Result of ps -aux is below
postgres 22129 0.0 0.1 1276896 37276 ? Ss 07:13 0:00 postgres: dbname: checkpointer process
postgres 22134 0.0 0.0 178008 4360 ? Ss 07:13 0:00 postgres: dbname: stats collector process
postgres 23030 18.5 0.9 1436048 316336 ? Ss 07:17 4:53 postgres: dbname: postgres sakura 127.0.0.1(56496) idle waiting for D1E/CEA4D9C8
I think stats process may be lock the server to restart.
I think it's locking to stop server, because after that I have to wait long time to only shutdown the PC. May be shutdown process is waiting until stats process stop.
Is there any way to stop stats process properly?
Or, the way to force top stats process?
I tried kill -9, but it does not help.

Debugging AccessExclusiveLock in Postgres 9.6

We have an application, backed by Postgres which briefly locked up. The Postgres logs showed a series of AccessExclusiveLock entries for pg_database:
[13-1] sql_error_code = 00000 LOG: process 7045 still waiting for AccessExclusiveLock on object 0 of class 1262 of database 0 after 1000.123 ms
[6-1] sql_error_code = 00000 LOG: process 7132 still waiting for AccessExclusiveLock on object 0 of class 1262 of database 0 after 1000.118 ms
[6-1] sql_error_code = 00000 LOG: process 8824 still waiting for AccessExclusiveLock on object 0 of class 1262 of database 0 after 1000.133 ms
[14-1] sql_error_code = 00000 LOG: process 7045 acquired AccessExclusiveLock on object 0 of class 1262 of database 0 after 39265.319 ms
[7-1] sql_error_code = 00000 LOG: process 7132 acquired AccessExclusiveLock on object 0 of class 1262 of database 0 after 12824.407 ms
[7-1] sql_error_code = 00000 LOG: process 8824 acquired AccessExclusiveLock on object 0 of class 1262 of database 0 after 6362.509 ms
1262 here refers to pg_database:
=> select 1262::regclass;
+-------------+
| regclass |
+-------------+
| pg_database |
+-------------+
We are running Postgres 9.6.5 on Heroku.
From what I understand, an AEL will be taken for "heavy" operations such as DROP TABLE, TRUNCATE, REINDEX [1]... Our runtime operations consist of a number of stored procedures, each of which insert/update/delete on multiple tables (deletes are rarer). We do not perform any of the operations listed above and in the linked documentation at runtime, and there were no releases/maintenance (by us) running at this time.
I haven't managed to find any documentation giving examples of when this lock could be taken during the "normal operation" outlined above. My questions are:
What could have caused the AELs (if I have given enough information to speculate) and are there any best-practices for avoiding them in future?
What else could I look at to help debug the cause?
[1]: Postgres docs - explicit locking

Fatal error starting postgres

I'm unfamiliar with how to use postgres and need some help. I'm currently running OSX Yosemite.
When I start postgres I get this:
pg_ctl: could not start server
Examine the log output.
There was an error executing [start] on postgres. Check /Users/work/git/proj/var/log/postgres.log for details.
createuser: could not connect to database postgres: FATAL: could not open relation mapping file "global/pg_filenode.map": No such file or directory
The log is below.
When I try to stop postgres I get this:
Postgres not running
And when I run ps -ef |grep postgres I get this:
20010 13398 1 0 Jul07 ? 00:00:00 /usr/pgsql-9.3/bin/postgres -h -k /Users/work/git/proj/var/pg
20010 13399 13398 0 Jul07 ? 00:00:09 postgres: logger process
20010 13401 13398 0 Jul07 ? 00:00:10 postgres: checkpointer process
20010 13402 13398 0 Jul07 ? 00:00:00 postgres: writer process
20010 13403 13398 0 Jul07 ? 00:00:00 postgres: wal writer process
20010 13404 13398 0 Jul07 ? 00:00:36 postgres: autovacuum launcher process
20010 13405 13398 0 Jul07 ? 00:00:02 postgres: stats collector process
20010 18112 17723 0 10:22 pts/0 00:00:00 grep postgres
What does this all mean and how could I possibly fix this?
log text
Postgres data dir doesn't exist. Creating
The files belonging to this database system will be owned by user "rose.smith".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /Users/work/git/proj/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /Users/work/git/proj/postgres/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
/usr/pgsql-9.3/bin/postgres -D /Users/work/git/proj/postgres
or
/usr/pgsql-9.3/bin/pg_ctl -D /Users/work/git/proj/postgres -l logfile start
waiting for server to start....< 2015-06-04 17:24:57.966 GMT >LOG: redirecting log output to logging collector process
< 2015-06-04 17:24:57.966 GMT >HINT: Future log output will appear in directory "pg_log".
done
server started
waiting for server to shut down.... done
server stopped
waiting for server to start....< 2015-06-04 18:10:18.044 GMT >LOG: redirecting log output to logging collector process
< 2015-06-04 18:10:18.044 GMT >HINT: Future log output will appear in directory "pg_log".
done
server started
"/Users/work/git/proj/var/log/postgres.log" 413L, 20935C
after running /usr/pgsql-9.3/bin/postgres -D /Users/work/git/proj/postgres
< 2015-07-08 14:40:36.331 GMT >FATAL: lock file "postmaster.pid" already exists
< 2015-07-08 14:40:36.331 GMT >HINT: Is another postmaster (PID 18145) running in data directory "/Users/work/git/proj/postgres"?
I can't speak to why this worked after trying these commands just a few minutes ago, but it is now working. Good luck to anyone else with the same problem.
stop postgres
killall postgres
remove postgres database with rm -rf postgres
start postgres
This website was helpful. I think my problem may have been the same as his.
I had deleted ~/Library/Containers/com.heroku.postgres or ~/Application Support/Postgres/ while the Postgres.app was still running. The old version was still running since I deleted the pid file, and it didn't know how to shut it down.
Source: https://github.com/PostgresApp/PostgresApp/issues/96
I faced same issue. I solved the problem with the following commands.
If you install postgresql using HomeBrew...
rm /usr/local/var/postgres/postmaster.pid
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Hope this helps you!

PostgreSQL insert data always fail process hang up

When i want insert a row to table.
It always hangs on waiting can not commit successful.
postgres 17941 2092 0 16:42 ? 00:00:00 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf
postgres 17943 17941 0 16:42 ? 00:00:00 postgres: writer process
postgres 17944 17941 0 16:42 ? 00:00:00 postgres: wal writer process
postgres 17945 17941 0 16:42 ? 00:00:00 postgres: autovacuum launcher process
postgres 17946 17941 0 16:42 ? 00:00:00 postgres: stats collector process
postgres 18326 17941 0 16:51 ? 00:00:00 postgres: admin gt_development 127.0.0.1(40309) COMMIT waiting for 0/1217CA98
Who can help me?
Thanks for reply.
I have fixed by pure reinstall the postgresql 9.1

Postgresql 9.0 is running in bg by default

I found that postgresql v9.0.7 is running in bg mode by default when it is started ( Command below ). Earlier when we were using postgresql v7.4.2 it used to run in foreground mode.
I am using freebsd 8.2 64 bit environment. Postgresql v9.0.7 is built with WITHOUT_XML, WITHOUT_GETTEXT and WITHOUT_GNUGEOPT options set.
c670e04:rkananth 16] /usr/local/bin/postgres --version
postgres (PostgreSQL) 9.0.7
c670e04:rkananth 7] setenv PGDATA /data/db/postgres/
c670e04:rkananth 11] /data/bin/runas pgsql /usr/local/bin/postgres
c670e04:rkananth 12] ps -A | grep post
65165 ?? Ss 0:00.01 /usr/local/bin/postgres
65167 ?? Ss 0:00.00 postgres: writer process (postgres)
65168 ?? Ss 0:00.00 postgres: wal writer process (postgres)
65169 ?? Ss 0:00.00 postgres: autovacuum launcher process (postgres)
65170 ?? Ss 0:00.00 postgres: stats collector process (postgres)
65224 0 S+ 0:00.00 grep post
c670e04:rkananth 14] ps -p 65165 -o ppid
PPID
1
c670e04:rkananth 15] ps 1
PID TT STAT TIME COMMAND
1 ?? SLs 0:00.17 /sbin/init --
c670e04:rkananth 16]
Are there any way where I can force it to come foreground?
Also looking at the above log, it shows that the server process's parent is set to 1 ( init) is it expected behavior when server runs in bg mode ?
However documentation for 9.0.7 says by default it should come in foreground. Why is this not happening in my case, may be a bug?
Update 1:
/data/bin/runas is not introducing any behavior change, tested without it. Same behavior is is also seen in v8.3 and on Freebsd 7.2 32-bit environment.
Server process becoming child of PID 1 ( init ) looks like a standard behavior of any application runs as a daemon.
My question now is - Is there a way where I can instruct Postgres not to run as Daemon ?
Update 2:
Got the solution it is the config "silent_mode = off" (By default it is on) will make it to run in foreground and process runs as child process of the shell. With this the question is answered.
( Source - http://postgresql.1045698.n5.nabble.com/BUG-4381-Postgresql-daemon-won-t-stay-in-the-foreground-td2127518.html )
Indeed, postgres should stay in the foreground, as stated in the manpage:
By default postgres starts in the foreground and prints log
messages to the standard error stream. In practical applications
postgres should be started as a background process, perhaps at
boot time.
Most likely the runas command is what daemonizes the postgres process. Try running postgres from a shell started as pgsql user:
root# su - pgsql
pgsql$ setenv PGDATA /data/db/postgres/
pgsql$ /usr/local/bin/postgres
You can also try with su(1) and sudo(8) if you don't like the idea of a shell as pgsql user.
Now I'm wondering why you need postgres to run in the foreground. Do you really have a good reason?