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
I can't figure out how to auto-restart mongodb on Ubuntu 16.04 in the event that it crashes due to memory-pressure.
I'm using supervisord for other scripts etc, but mongod is through systemctl and I'm not sure how that ties into it.
Figured it out:
Edit your mongod service: sudo vim /lib/systemd/system/mongod.service
Add Restart=always under service
Reload systemctl daemon: sudo systemctl daemon-reload
Now whenever mongod gets killed. It'll get respawned by systemctl.
When you install mongoDB just run systemctl enable mongod.service on terminal.
This will make your mongoDB service auto-start on every restart.
I changed the postgres data directory following this steps:
sudo systemctl stop postgresql
sudo rsync -av /var/lib/postgresql /mnt/volume-nyc1-01
sudo nano /etc/postgresql/10/main/postgresql.conf
then I edited postgresql.conf:
data_directory = '/mnt/volume-nyc1-01/postgresql/9.5/main'
sudo systemctl start postgresql
The new directory data is owned by the postgres user.
The problem is that, after starting ubuntu the postgres cluster is down.
I run the command pg_lsclusters and got the answer:
10 main 5432 down <unknown> /mnt/volume-nyc1-01 /var/log/postgresql/postgresql-10-main.log
And after run sudo systemctl start postgresql#10-main the cluster starts and postgres works ok.
So what can I do to fix this and the clusters starts normally after Ubuntu starts?
You're editing the PostgreSQL version 9.5 configuration file, as indicated by the directory name. However, the cluster you actually have and are starting is PostgreSQL 10, and probably has a configuration file in a different location. Straighten out the agreement between configuration files, PostgreSQL versions, and systemd unit files, and the cluster should start up automatically.
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
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