I want to restart my postgres using command
sudo service postgresql restart
However I'm getting the following error:
[warn] No PostgreSQL clusters exist; see "man pg_createcluster" ...
(warning).
I already have postgres running, showing through ps aux:
# ps aux| grep postgres
postgres 1 0.0 1.1 287484 24328 ? Ss 21:58 0:00 postgres
postgres 77 0.0 0.4 287608 8588 ? Ss 21:58 0:00 postgres: checkpointer process
postgres 78 0.0 0.1 287484 3884 ? Ss 21:58 0:00 postgres: writer process
postgres 79 0.0 0.4 287484 8680 ? Ss 21:58 0:00 postgres: wal writer process
postgres 80 0.0 0.3 287896 6640 ? Ss 21:58 0:00 postgres: autovacuum launcher process
postgres 81 0.0 0.1 142612 3120 ? Ss 21:58 0:00 postgres: stats collector process
root 1253 0.0 0.0 12788 972 pts/0 S+ 22:31 0:00 grep postgres
Now searching online, I found this post. I followed the solution to create a cluster:
sudo pg_createcluster 9.6 main
sudo service postgresql stop
sudo service postgresql start
After this, I am able to "restart" posgres through
sudo service postgresql restart
HOWEVER, this is not on the original cluster. As if I run ps-aux, I see a new cluster setup, this is not what I want.
# ps aux| grep postgres
postgres 1 0.0 1.1 287484 24328 ? Ss 21:58 0:00 postgres
postgres 77 0.0 0.4 287608 8588 ? Ss 21:58 0:00 postgres: checkpointer process
postgres 78 0.0 0.1 287484 3884 ? Ss 21:58 0:00 postgres: writer process
postgres 79 0.0 0.4 287484 8680 ? Ss 21:58 0:00 postgres: wal writer process
postgres 80 0.0 0.3 287896 6640 ? Ss 21:58 0:00 postgres: autovacuum launcher process
postgres 81 0.0 0.1 142612 3120 ? Ss 21:58 0:00 postgres: stats collector process
postgres 1292 0.0 1.2 287628 25680 ? S 22:42 0:00 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
postgres 1294 0.0 0.1 287628 3944 ? Ss 22:42 0:00 postgres: 9.6/main: checkpointer process
postgres 1295 0.0 0.1 287628 3940 ? Ss 22:42 0:00 postgres: 9.6/main: writer process
postgres 1296 0.0 0.1 287628 3944 ? Ss 22:42 0:00 postgres: 9.6/main: wal writer process
postgres 1297 0.0 0.3 288056 6464 ? Ss 22:42 0:00 postgres: 9.6/main: autovacuum launcher process
postgres 1298 0.0 0.1 142620 3172 ? Ss 22:42 0:00 postgres: 9.6/main: stats collector process
root 1329 0.0 0.0 12788 968 pts/0 S+ 22:42 0:00 grep postgres
All the start/restart/stop is all applied to the new cluster. I just want to restart the original cluster. How can I do that?
I found that this happened because the postgresql db was running inside a container. To restart the database, I'll need to restart the docker container
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 installed postgres using brew.
DYadav-MBP-2:~ dyadav$ brew install postgresql#9.6
Below is my .bash_profile file.
DYadav-MBP-2:~ dyadav$ cat .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export PATH=/usr/local/opt/postgresql#9.6/bin/:$PATH
I have also added 127.0.0.1 postgres to /etc/hosts.
Started postgres using below's command:
brew services start postgresql#9.6
But when I run psql postgres, I get "psql: FATAL: role "dyadav" does not exist"
I following many solutions provided in stack overflow, nothing really helped.
fyi: postgres is running on user dyadav.
DYadav-MBP-2:~ dyadav$ ps aux | grep postgres
dyadav 2338 0.0 0.0 4340528 896 ?? Ss 8:12AM 0:00.05 postgres: stats collector process
dyadav 2336 0.0 0.0 4485592 1968 ?? Ss 8:12AM 0:00.04 postgres: autovacuum launcher process
dyadav 2335 0.0 0.0 4485528 1000 ?? Ss 8:12AM 0:00.05 postgres: wal writer process
dyadav 2334 0.0 0.0 4485528 2020 ?? Ss 8:12AM 0:00.08 postgres: writer process
dyadav 2332 0.0 0.0 4485528 1072 ?? Ss 8:12AM 0:00.00 postgres: checkpointer process
dyadav 2302 0.0 0.1 4485808 17252 ?? S 8:12AM 0:00.06 /usr/local/opt/postgresql#9.6/bin/postgres -D /usr/local/var/postgresql#9.6
dyadav 4641 0.0 0.0 4268056 804 s000 S+ 9:41AM 0:00.00 grep postgres
psql assumes you want to connect to the database as the current operating system user. So psql postgres tries to connect to a database named postgres using the database user dyadav.
As you want to create a database you need to connect as the superuser postgres (a database user, not an operating system user):
psql -d postgres -U postgres
-d specifies the database to connect to, -U specifies the database user to use.
Then you can run the create database command to create another database.
I installed PostgreSQL 9.6 on my Ubuntu 16.04 system. It seems like it's up and running, but when I try to make a connection it just fails. When I run the status command I see that it's always saying exited for some reason. I see lots of things in a google search but none seem to be helping.
I changed the first entry in the pg_hba.conf to be local all postgres trust
% ps augxw | grep postg
postgres 769 0.0 0.3 303964 24384 ? S 22:13 0:00 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
postgres 772 0.0 0.0 303964 3956 ? Ss 22:13 0:00 postgres: 9.6/main: checkpointer process
postgres 773 0.0 0.0 303964 3956 ? Ss 22:13 0:00 postgres: 9.6/main: writer process
postgres 774 0.0 0.0 303964 3956 ? Ss 22:13 0:00 postgres: 9.6/main: wal writer process
postgres 775 0.0 0.0 304408 6572 ? Ss 22:13 0:00 postgres: 9.6/main: autovacuum launcher process
postgres 776 0.0 0.0 158964 3204 ? Ss 22:13 0:00 postgres: 9.6/main: stats collector process
ubuntu 1492 0.0 0.0 12944 936 pts/0 S+ 22:14 0:00 grep postg
%
% sudo su - postgres
$ psql -h localhost
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
$ exit
logout
% systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2017-03-30 22:13:57 PDT; 1min 19s ago
Process: 901 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 901 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CPU: 0
CGroup: /system.slice/postgresql.service
Mar 30 22:13:57 ip-172-31-9-223 systemd[1]: Starting PostgreSQL RDBMS...
Mar 30 22:13:57 ip-172-31-9-223 systemd[1]: Started PostgreSQL RDBMS.
You are connecting using TCP/IP socket, but local refers to unix-domain socket.
The first field is the connection type: "local" is a Unix-domain socket, "host" is either a plain or SSL-encrypted TCP/IP socket, "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a plain TCP/IP socket.
I did install postgresql-9.6 from that repo and:
host all postgres 127.0.0.1/32 trust does what you want to do
postgres#lkaminski-ubuntu-desk:~$ psql works out of the box, no need to change config. It is using unix-domain socket that is already trusted. So you can just drop -h localhost and no need to edit configs.
$ sudo grep -e "^[^#]" /etc/postgresql/9.6/main/pg_hba.conf
local all postgres peer
host all postgres 127.0.0.1/32 trust
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
The issue ended up being that version 9.5 had the normal 5432 port and so when 9.6 got installed/started, it pointed to 5433. Deleting the 9.5 install and editing the config file to point at 5432 fixed the issue.
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
I am trying to debug some shared memory issues with Postgres 9.3.1 and CentOS release 6.3 (Final). Using top, I can see that many of the postgres connections are using shared memory:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3534 postgres 20 0 2330m 1.4g 1.1g S 0.0 20.4 1:06.99 postgres: deploy mtalcott 10.222.154.172(53495) idle
9143 postgres 20 0 2221m 1.1g 983m S 0.0 16.9 0:14.75 postgres: deploy mtalcott 10.222.154.167(35811) idle
6026 postgres 20 0 2341m 1.1g 864m S 0.0 16.4 0:46.56 postgres: deploy mtalcott 10.222.154.167(37110) idle
18538 postgres 20 0 2327m 1.1g 865m S 0.0 16.1 2:06.59 postgres: deploy mtalcott 10.222.154.172(47796) idle
1575 postgres 20 0 2358m 1.1g 858m S 0.0 15.9 1:41.76 postgres: deploy mtalcott 10.222.154.172(52560) idle
...
There are about 29 total idle connections. However, sudo ipcs -m only shows:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x0052e2c1 163840 postgres 600 48 21
Surprisingly, it only shows it using 48 bytes. Why doesn't ipcs show a larger segment? Is there a different command I should be using?
I think it is because your postgre is of version 9.3, which uses POSIX type of shared memory. And ipcs -m shows sysV shared memory segments, which were used in Postgre of prior versions.