The original postgres server was run on ubuntu , but the machine crash and can't boot .
I tried to mount the disk on the Ubuntu live with the postgres installed , and then change the data_directory to the path of the oringinal data_directoty which I mount ,but it failed.
There is no error message when I run systemctl start postgresql ,but when I try to login with psql ,it show
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
It seem that the server is not on. How can I fix it ?
Or is there any other way to get the database without booting the original machine?
I have found the problem,
The privilege of data_directory should
be 700 ,but I set to 777sudo chmod -R <data_dir> 700
The owner of data_directory should be postgressudo chown -R postgres:postgres <data_dir>
Related
I'm using WSL with an ubuntu 18.04 distribution, in the bash I hit sudo -u postgres psql
I get the following error:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting connections on
Unix domain socket "/var/run/postgresql/.s.PGSQL.5433"?
Then I tried other postgres operations like: sudo -u createdb mydb
only to get the same error.
Please advise.
When running PostgreSQL on Ubuntu in Windows Subsystem for Linux, you may have to manually start the db server before you can connect. Use the command below to start your db server and then try connecting.
sudo service postgresql start
OR
sudo /etc/init.d/postgresql start
You can also check the status of the db server with:
sudo service postgresql status
I am using CentOS 7.3 as a guest VM from Oracle VirtualBox. The host is Windows 7 and I have a physical USB stick (aka flash drive) to house the data directory for Postgres. I can use a USB stick as a mounted directory in Linux. I can read and write files to it.
I expect to be able to have Postgres databases on my USB stick. But I cannot get Postgres databases on my USB stick. I installed Postgres on the Linux VM.
To change the default data directory of Postgres, I followed these directions.
If you do not have time to go to the link, I simply installed Postgres with these two commands:
yum -y install postgresql-server postgresql-contrib
postgresql-setup initdb
then I ran these two commands:
mv /var/lib/pgsql/data/* /mnt/windows-share/data
ln -s /mnt/windows-share /var/lib/pgsql/data
Afterward I try to start the Postgres service, I get an error.
Here is the command that I try (as root):
systemctl start postgresql
Here is the error:
Job for postgresql.service failed because the control process exited
with error code. See "systemctl status postgresql.service" and
"journalctl -xe" for detail.
I tried systemctl status postgresql.service and I found this:
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled
vendorpreset: disabled)
Active: failed (Result exit-code)... Process ...
ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited,
status=1/FAILURE)
... failed to start PostgreSQL... ...Unit postgresql.service...
...postgresql.service failed
I used journalctl -xe but that did not tell me anything meaningful.
To change the default data directory of Postgres, I tried this:
postgresql-setup initdb --pgdata=/mnt/windows-share/
But I got
failed to find PGDATA setting in --pgdata=/mnt/mar/data.service
How do I get Postgres installed with a customized data directory? I need it to be in a the "/mnt/" directory. I want to create all my databases on a USB stick.
To install Postgres on a customized location (e.g. home/postgres directory) follow these steps
install the required version of Postgres e.g. 13
create postgres directory in Home. and grant its access to posgres user
mkdir postgres
chown postgres:postgres postgres
usermod -m -d /home/postgres postgres
Move data directory to the new location as:
rsync -av /var/lib/pgsql/ /home/postgres/
update the location in postgres server as:
find / -name postgresql-9.5.service
vi /usr/lib/systemd/system/postgresql-9.5.service
update the data location in the file:
from the old location, e.g.
# Location of database directory
Environment=PGDATA=/var/lib/pgsql/13/data/
to the new location, e.g.
# Location of database directory
Environment=PGDATA=/home/postgres/13/data/"
Stop postgres, reload deamon and start postgres
stop postgres
systemctl daemon-reload
start postgres
Done...
I' ve solved the same problem on CentOS 6
Maybe u can try it.
Add your disk
Check your disk is existing (in my case new disk is /dev/sdb1/)
# fdisk -l
Mount new disk
# mkdir /hdd2
# mount -t ext3 /dev/sdb1 /hdd2/
Auto mount hard disk by add new line:
# vi /etc/fstab
Add line: /dev/sdb1 /hdd2 ext3 defaults 0 0
Config postgres
# service postgresql stop
# vi /etc/sysconfig/pgsql/postgresql
Add line: PGDATA=/hdd2/data
# service postgresql start
Hope it useful to you!!
I'm getting the following error when I try to run "mongod" in the terminal. I've tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to get it working would be amazing.
ERROR:
dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
Side note:
Node also stopped working on my machine around the same time that I got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
Any help would be much appreciated!
This should work to ensure that the directory is set up in the right place so that Mongo can find it:
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
You need to create the directory on root /data/db or set any other path with the following command :
mongod --dbpath /srv/mongodb/
See the example link
I solved the problem with :
sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.
Change the user of the new data directory:
chown mongodb [rute_directory]
And try another time to start the mongo service
service mongod start
I solve the same problem with this.
Daemons (usually ending with d) are normally started as services. Starting the service (daemon) will allow mongodb to work as designed (without permission changes if integrates well with your distro). I start it using the service named mongodb instead of starting mongod directly--on distro with systemd enable on startup then run like:
sudo systemctl enable mongodb
sudo systemctl start mongodb
or, on distro with upstart (if you have /etc/init) or init (if you have /etc/init.d) ( https://www.tecmint.com/systemd-replaces-init-in-linux/ ) instead run:
sudo service mongodb enable
sudo service mongodb start
If you have a distro with rc ("run commands") such as Gentoo (settings in /etc/init.d) (https://forums.gentoo.org/viewtopic-t-854138-start-0.html) run:
rc-update add mongodb default
/etc/init.d/mongodb start
In a distro/version of FreeBSD which still has rc (check whether your version switched to systemd, otherwise see below):
add the following line to /etc/rc.conf:
mongod_enable="YES"
then:
sudo service mongod start
After starting the service, an unpriveleged user can use mongo, and each user will have separate data.
I also got the error that "The file /data/db doesn't exist" when I tried to save my file using the "mkdir -p /data/db" command(using both with and without sudo command). But later on one site, a person named Emil answered that the path "/data/db" no longer works on Mac, so use "~/data/db" instead
i.e., use the command
mkdir -p ~/data/db
instead of previous command.
Moreover, use
mongod --dbpath ~/data/db
to run mongod
It worked for me, hope it work for others too facing the same problem
I downloaded postgresql-9.1.
but when I execute the command in terminal:
$ createdb mydb
I get the following message:
createdb: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
please tell me how to sort this problem.I have even tried to uninstall and then reinstall it. I am trying to run this on linux mint 15 (cinnamon).
Use ps to see if the postgresql process is actually running. If not, start it (service postgresql start). Normally should start up itself on boot after installation but who knows. Also, some error may prevent it from starting on boot.
If postgresql is running, then you may need to edit pg_hba.conf in the data directory. Again, normally the database should listen for local connections by default but who knows.
I am trying to connect to a MongoDB instance running on a remote Linux server. The connection attempt is timing out leading me to suspect network settings on the Linux server as I can ssh to the server and connect to MongoDB locally.
/etc/mongod.conf does not have the bind_ip set, so that is not the issue.
Can anyone point me to how I can troubleshoot this problem?
Can you telnet to the MongoDB port from the remote host and connect successfully?
If so, that means the port is open, the connection works and it's not a firewall/iptables etc. issue. You should look into the next piece - do you have authentication enabled?
If you can't connect with telnet, then something is blocking you from getting from the remote host to that port. It could be firewall, or it could be on the host - it really depends on your set up and infrastructure.
Remove any lock acquired by the mongoDB
sudo rm -rf /data/configdb/mongod.lock;
Create the data directories for the config and shard servers
sudo mkdir /data;
sudo mkdir /data/db;
sudo mkdir /data/configdb;
sudo chown -R ubuntu:ubuntu /data;
sudo chmod -R 755 /data
Give the rights to the above created folders.
Give ownership to the above created folders.
Now try to connect to mongodb, It will surely connect now.