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?
Related
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.
I ran
brew postgresql-upgrade-database
and after a long series of updates the final results are:
==> Migrating and upgrading data...
Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking database user is the install user ok
Checking database connection settings ok
Checking for prepared transactions ok
Checking for reg* data types in user tables ok
Checking for contrib/isn with bigint-passing mismatch ok
Checking for tables WITH OIDS ok
Checking for invalid "sql_identifier" user columns ok
Creating dump of global objects ok
Creating dump of database schemas
ok
Checking for presence of required libraries fatal
Your installation references loadable libraries that are missing from the
new installation. You can add these libraries to the new installation,
or remove the functions using them from the old installation. A list of
problem libraries is in the file:
loadable_libraries.txt
Failure, exiting
Error: Upgrading postgresql data from 11 to 12 failed!
==> Removing empty postgresql initdb database...
==> Moving postgresql data back from /usr/local/var/postgres.old to /usr/local/var/postgres...
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
Error: Failure while executing; `/usr/local/opt/postgresql/bin/pg_upgrade -r -b /usr/local/Cellar/postgresql#11/11.9/bin -B /usr/local/opt/postgresql/bin -d /usr/local/var/postgres.old -D /usr/local/var/postgres -j 16` exited with 1.
The only notes about this I could find were about pg developers mulling whether to print out the offending databases involved: it was unclear what the fix would be. Any hints ?
Update There is no loadable_libraries.txt in the directory that this was run.
I am creating an answer based on the comment from #LaurenzAlbe. The loadable_libraries.txt was not placed in the current directory from which the command
was run . Instead let's go find where it went:
$find / -name loadable_libraries.txt
/usr/local/var/log/loadable_libraries.txt
So what's in that file?
06:22:24/cidervuong2 $cat /usr/local/var/log/loadable_libraries.txt
could not load library "$libdir/pg_background": ERROR: could not access file "$libdir/pg_background": No such file or directory
Database: bluej
I looked into that error:
ERROR: could not access file "$libdir/pg_background"
and there is no useful information. I went ahead and nuked postgresql again and this time it installed cleanly.
brew uninstall --ignore-dependencies postgres
brew install postgres
brew services start postgresql # actually already started
and pg came up cleanly this time
502 84118 1 0 6:33AM ?? 0:00.03 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres
502 84120 84118 0 6:33AM ?? 0:00.00 postgres: checkpointer
502 84121 84118 0 6:33AM ?? 0:00.03 postgres: background writer
502 84122 84118 0 6:33AM ?? 0:00.01 postgres: walwriter
502 84123 84118 0 6:33AM ?? 0:00.01 postgres: autovacuum launcher
502 84124 84118 0 6:33AM ?? 0:00.01 postgres: stats collector
502 84125 84118 0 6:33AM ?? 0:00.00 postgres: logical replication launcher
I install postgresql9.4.5 by homebrew.
Before 9.4.5, I used 9.3.9 by macport, but I want to use only homebrew.
So I uninstall 9.3.9 and macport and install 9.4.5 by homebrew.
I could success "initdb /usr/local/var/postgres".
But, when I enter "postgres -D /usr/local/var/postgres", show error.
The error
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
I tyied to start server by manual
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
But, pg_ctl -D /usr/local/var/postgres status show pg_ctl: no server running.
I confirmed pg_hba.conf and it shows
# IPv4 local connections:
host all all 127.0.0.1/32 trust
Also, when I enter psql, shows the error psql: FATAL: could not open relation mapping file "global/pg_filenode.map": No such file or directory
What do I need to do? Please tell me.
Add a postscript
I also tried ps aux | grep postgres
postgres 276 0.0 0.0 2470236 452 ?? Ss 火12AM 0:03.18 postgres: stats collector process
postgres 275 0.0 0.0 2614684 1160 ?? Ss 火12AM 0:11.63 postgres: autovacuum launcher process
postgres 274 0.0 0.0 2614552 416 ?? Ss 火12AM 0:00.79 postgres: wal writer process
postgres 273 0.0 0.0 2614552 440 ?? Ss 火12AM 0:00.81 postgres: writer process
postgres 272 0.0 0.0 2614552 596 ?? Ss 火12AM 0:00.07 postgres: checkpointer process
postgres 242 0.0 0.0 2614552 1184 ?? S 火12AM 0:01.07 /opt/local/lib/postgresql93/bin/postgres -D /opt/local/var/db/postgresql93/defaultdb
root 75 0.0 0.0 2469228 884 ?? Ss 火12AM 0:00.03 /opt/local/bin/daemondo --label=postgresql93-server --start-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper restart ; --pid=none
This shows some process is active. And, 2 lines show macport pass. But, I had deleted /opt/local folder.
I killed these process and ps aux | grep postgres did not show anything.
So, I tried postgres -D /usr/local/var/postgres. Next time, this shows
LOG: database system was shut down at 2015-11-19 18:45:38 JST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
And, the terminal stopped and did not show prompt. So I had to enter 'control + c'
But, I could start postgres manually. I did this command pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
And I could do psql commands.
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!
I'm getting a common Mac OSX error for Homebrew installations of Postgres,
No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
This is apparently due to there being multiple installs on the system. However, the usual steps are not resolving things.
I can successfully start Postgres and running:
ps auxw | grep post
returns ..
euanmillar 847 0.0 0.0 2432768 588 s000 R+ 11:19am 0:00.00 grep postgres
euanmillar 845 0.0 0.0 2439324 448 ?? Ss 11:19am 0:00.00 postgres:
stats collector process
euanmillar 844 0.0 0.0 2443176 1520 ?? Ss 11:19am 0:00.00 postgres:
autovacuum launcher process
euanmillar 843 0.0 0.0 2443044 544 ?? Ss 11:19am 0:00.00 postgres: wal writer process
euanmillar 842 0.0 0.0 2443044 584 ?? Ss 11:19am 0:00.00 postgres: writer process
euanmillar 841 0.0 0.0 2443044 596 ?? Ss 11:19am 0:00.00 postgres: checkpointer process
euanmillar 839 0.0 0.0 2443044 3616 s000 S 11:19am 0:00.02 /us
so it looks like postgres is running.
I have commented in the following lines in postgresql.conf
port = 5432
unix_socket_directory = '/var/pgsql_socket'
unix_socket_permissions = 0777
and in var/pgsql_socket/ I do have a hidden file .s.PGSQL.5432
I have tried solutions to many of the posts here. This one especially seems similar:
https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-why
But the difference is that I do have a '/var/pgsql_socket' directory which is CHOWN-ed to everyone. I have used Homebrew to completely remove and re-install Postgres and still I have the same issue.
You need to remove the postmaster.pid, which should be in the following path:
/usr/local/var/postgres/postmaster.pid
For me, i removed postmaster.pid in /usr/local/var/postgres. fixed me right up.
A simpler solution is to locate where the socket actually is vs where it's expected to be. In my case, I ran:
$ locate PGSQL.5432
/private/var/pgsql_socket/.s.PGSQL.5432
/private/var/pgsql_socket/.s.PGSQL.5432.lock
Then just symlink the expected socket location to the actual socket location.
$ ln -s /private/var/pgsql_socket/.s.PGSQL.5432 /tmp/.s.PGSQL.5432
The system client is being used and not your brew version. The symlink approach only lasts until the next restart. This approach fixes the root issue I believe
sudo edit /etc/paths
Move the line containing /usr/local/bin to the top of the file. (Before /usr/bin)
Uninstall your postgres gem(s) (gem uninstall pg)
Start up new shell to load the new environment settings
bundle
That is not an OS X specific issue. You will need to clean up your postgres installation and then reinstall it again. I have faced this issue on my ubuntu 12.04. While cleaning your previous installation, you will need to remove all packages starting with postgres (postgresql, postgresql-common, postgresql-client etc), in other words, postgres*. I have not used brew, have used port on OS X Lion. I guess the equivalent command should be sudo brew remove postgres*. A sudo brew install postgresql should then do the trick.
Also, if you feel the server is already running, you can try sudo -u postgres createuser. If that fails, you will need to reinstall.
However, the output of your ps aux | grep post is actually the grep command itself. Not of the postgres server running.
EDIT: Looks like the following link could be of help https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-why
If yes, then this question might be a duplicate.
I had the same problem on Mac Serria. In Mac Serria you can find postmaster.pid inside /Users/<user_name>/Library/Application Support/Postgres/var-9.6 if you used GUI installer rather than homebrew.
Once you delete this file then everything should work fine.