Weird systemctl behavior - postgresql

I installed Postgres9.6 on my Ubuntu 16.04 through apt-get. and I installed the same version on an AWS ubuntu instance to try replication.
I was following the steps from this blog:
http://www.rassoc.com/gregr/weblog/2013/02/16/zero-to-postgresql-streaming-replication-in-10-mins/
Now I can log to the postgres user on both machines, and run psql and execute all database operations. But when I check the status of the server (on both machines) using sudo systemctl status postgres.service, I get this:
● postgres.service Loaded: not-found (Reason: No such file or
directory) Active: inactive (dead)
Which is weird because I can run psql, right?
And this prevents me from creating remote connections.

Related

System has not been booted with systemd ERROR when updating Postgresql in Ubuntu

I've been following this link to update Postgresql on my Ubuntu-18.04 (VM running on Windows 10)
https://computingforgeeks.com/install-postgresql-12-on-ubuntu/
However, Im getting the below error, so I cannot proceed.
.../desktop/my_app$ systemctl status postgresql.service
System has not been booted with systemd as init system (PID 1). Can't operate.
What can I do?
service postgresql status
or
systemctl status postgresql
Must work.

how to make mongo db start after ubuntu startup

mongo connection failed in terminal every time after ubuntu startup then after running the command sudo service mongod start it is working fine. I am using ubuntu 18.04. How to fix it that it may run always without the above command?
Try below:
sudo systemctl enable mongod
Reboot your machine and check if the service is up.
sudo systemctl status mongod
Checking out the manpage will give you a lot of information.
See systemctl manpage
http://manpages.ubuntu.com/manpages/cosmic/en/man1/systemctl.1.html

Reboot and poweroff 'destructive' on Ubuntu 16.04

When I try to reboot or turn off my laptop, it doesn't work. After investigating a little further:
$ systemctl status reboot.target
● reboot.target - Reboot
Loaded: loaded (/lib/systemd/system/reboot.target; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd.special(7)
reboot is disabled. However, trying to enable it with systemctl enable reboot.target results in this output:
Failed to execute operation: File exists
After running reboot, I get the following error:
Failed to start reboot.target: Transaction is destructive.
See system logs and 'systemctl status reboot.target' for details.
I have no idea what to do; for now I'll just force poweroff, but I'd like to be able to use the reboot and shutdown functionality without cutting power every time I want to turn it off.
As documented in man systemctl, "enabling" a service typically means that you want it to run at boot. If the "reboot" target was enabled, you would be instructing your laptop to be rebooted as part of the boot process. That's probably not what you want.
In /etc/systemd/journald.conf, set Storage=persistent.
Then:
systemctl daemon-reload
After your next failed sudo reboot, check the contents of your systemd journal file to see if you can find something hanging during shutdown.

PostgreSQL Services

Can someone give a detailed explanation of how the postgresql service(s) works on Ubuntu [16.04]? The behavior that leads me to ask is the following. I use the command sudo systemctl start postgresql to start my postgresql service. When I run systemctl list-units | grep post I see
UNIT LOAD ACTIVE SUB DESCRIPTION
postgresql.service loaded active exited PostgreSQL RDBMS
postgresql#9.6-main.service loaded active running PostgreSQL Cluster 9.6-main
system-postgresql.slice loaded active active system-postgresql.slice
and when I run sudo systemctl stop postgresql both postgresql.service and postgresql#9.6-main.service disappear. What is each of these three services doing?
I assume postgresql#9.6-main.service is registered service for PostgreSQL Cluster 9.6-main cluster. This is the one that actually controls postgres on your system.
I assume postgresql.service is the effect desribed here
I assume system-postgresql.slice is a postgres slice unit
none of above are critical for running postgres. You can start/stop the cluser with just pg_ctl, without registering it with your services. But if you wonder which service runs it in your case - then it is postgresql#9.6-main.service

How to restart Postgresql

I have PostgreSQL 9.3 and 9.4 installed on my Linux Mint machine.
How can I restart PostgreSQL 9.4?
A method to restart both versions together is also fine.
Try this as root (maybe you can use sudo or su):
/etc/init.d/postgresql restart
Without any argument the script also gives you a hint on how to restart a specific version
[Uqbar#Feynman ~] /etc/init.d/postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ...]
Similarly, in case you have it, you can also use the service tool:
[Uqbar#Feynman ~] service postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force reload|status} [version ...]
Please, pay attention to the optional [version ...] trailing argument.
That's meant to allow you, the user, to act on a specific version, in case you were running multiple ones. So you can restart version X while keeping version Y and Z untouched and running.
Finally, in case you are running systemd, then you can use systemctl like this:
[Uqbar#Feynman ~] systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-11-14 12:33:35 CET; 7min ago
...
You can replace status with stop, start or restart as well as other actions. Please refer to the documentation for full details.
In order to operate on multiple concurrent versions, the syntax is slightly different. For example to stop v12 and reload v13 you can run:
systemctl stop postgresql-12.service
systemctl reload postgresql-13.service
Thanks to #Jojo for pointing me to this very one.
Finally Keep in mind that root permissions may be needed for non-informative tasks as in the other cases seen earlier.
You can also restart postgresql by using this command, should work on both the versions:
sudo service postgresql restart
On Windows :
1-Open Run Window by Winkey + R
2-Type services.msc
3-Search Postgres service based on version installed.
4-Click stop, start or restart the service option.
On Linux :
sudo systemctl restart postgresql
also instead of "restart" you can replace : stop or status.
This should work:
sudo systemctl stop postgresql
sudo systemctl start postgresql
The right way to restart postgres server is to use
pg_ctl restart -D /home/postgres/postgresdbdata/
pg_ctl is usually found in location usr/local/pgsql/bin/pg_ctl if u dont have it added to your path.
Documentation can be found here
https://www.postgresql.org/docs/13/app-pg-ctl.html
This has more details on Start,Stop,Restart,etc of the postgres server.
You can firstly check for the postgress process running
ps -ef | grep post
You might need to use (post|pg) on the grep side, to discover the process for the Postgres service running on your machine, it might depend on your OS.
And you can just kill the child process since most of this process should restart automatically.
sudo kill $pid_of_the_child_process
macOS:
On the top left of the MacOS menu bar you have the Postgres Icon
Click on it this opens a drop down menu
Click on Stop -> than click on start