PostgreSQL server failed to start, could not create lock file: permission denied - postgresql

I am attempting to install and run a postgreSQL server, whenever I install it using
sudo apt-get install postgresql
I get the following error:
* Starting PostgreSQL 9.1 database server
* The PostgreSQL server failed to start. Please check the log output:
2014-04-03 17:18:16 PDT FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
[fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing postgresql-common (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of postgresql-9.1:
postgresql-9.1 depends on postgresql-common (>= 115~); however:
Package postgresql-common is not configured yet.
dpkg: error processing postgresql-9.1 (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of postgresql:
postgresql depends on postgresql-9.1; however:
Package postgresql-9.1 is not configured yet.
dpkg: error processing postgresql (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while
processing:
postgresql-common
postgresql-9.1
postgresql
E: Sub-process /usr/bin/dpkg returned an error code (1)
I am guessing it's a permissions issue; how do I go about solving it?
I am running Ubuntu 13.10

Change the owner of /var/run/postgresql and set it to postgres:
sudo chown -R postgres:postgres /var/run/postgresql
If the user you are running as does not have sudo privilege, then
Change to root:
su -
Change ownership of /var/run/postgresql to user postgres and group postgres:
chown -R postgres:postgres /var/run/postgresql
I had the same problem when installing postgres on Ubuntu 14.04 and changing the ownership fixed the problem for me.

The lock file ends up in /var/run. To fix the permissions of this dir, I needed to run sudo chmod a+w /var/run/postgresql.

Could you check the file permissions of /var/run?
ls -l /var/run
If 'write' permission is missing, try
sudo chmod o+w /var/run

Related

Postgres 13 fails at the initdb stage

I've followed the official installation instructions for my Centos 7 machine:
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Install PostgreSQL:
sudo yum install -y postgresql13-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
The issue comes at the initdb stage. Instead of getting the typical "OK" at the end of execution, I'm given nothing. After looking through the postgresql-13-setup script, I managed to find an ouput log at /var/lib/pgsql/13/initdb.log:
/usr/pgsql-13/bin/initdb: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
It looks like, for whatever reason, libpq.so.5 (which is present in other past postgres installs) is missing from /usr/pgsql-13/lib/.
I've tried uninstalling/reinstalling postgres-13 multiple times now, clearing out the service, deleting all the directories, etc. This issue is only happening in this specific machine (I've installed postgres 13 in various other similar machines with no issue).
edit:
Ad requested, running:
/usr/pgsql-13/bin/initdb -E UTF8 /var/lib/pgsql/13/data
Returns the same exact error:
/usr/pgsql-13/bin/initdb: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

What does it mean to have a "masked" clickhouse-server?

I am new to clickhouse.
After several unfruitful attempts to install version 18.16.1, I purged both clickhouse-server and clickhouse-client (sudo dpkg --purge clickhouse-server and sudo dpkg --purge clickhouse-common).
After I made sure that sudo apt --fix-broken install did not return any error message, I went over and installed both the client and server using apt: sudo apt install clickhouse-server clickhouse-client.
Upon installation I received the following warning:
dpkg: warning: clickhouse-server: conffile
'/etc/systemd/system/clickhouse-server.service' is not a plain file or
symlink (= '/dev/null')
Trying service clickhouse-server status returned:
● clickhouse-server.service
Loaded: masked (Reason: Unit clickhouse-server.service is masked.)
Active: inactive (dead)
What does it mean to have a masked service? I found this post on AskUbuntu, but it seems specific to PostgreSQL. Am I OK to implement the solution provided in there to "unmask" the clickhouse service?
Not related to CH. Related to https://en.wikipedia.org/wiki/Systemd.
https://medium.com/#codingmaths/service-masking-in-linux-f7265d9b2181
mask is a stronger version of disable. Using disable all symlinks of the specified unit file are removed....
Denny Crane was right.
You need to run the following commands
systemctl unmask clickhouse-server
systemctl start clickhouse-server

How to connect to monogdb

I have set up the database on Mongodb Atlas and have connected to the database via application however it is not connecting to the database, I have tried using the Mongo shell also
I have tried to set up a new connection thinking it may be a corrupt file on my project but it still has the same issue. I also tried to run:
sudo apt update
sudo apt install -y mongodb
sudo systemctl status mongodb
but i get:
dpkg: error processing package mongodb (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
mongodb-server
mongodb
likewise if i try sudo service mongodb restart it then displays:
Tue Apr 2 21:16:28.214 Error: Invalid port number "//testdb-sc1hr.mongodb.net" in connection string "mongodb+srv://testdb-sc1hr.mongodb.net/cookbook" at src/mongo/shell/mongo.js:134
exception: connect failed
I have tried using sudo apt remove but i also get
invoke-rc.d: initscript mongodb, action "start" failed.
dpkg: error processing package mongodb-server (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mongodb:
mongodb depends on mongodb-server (>= 1:2.4.1-2); however:
Package mongodb-server is not configured yet.
Im very new to this and i feel like im just going round in circles now.
I have also tried connecting with mongodb compass but it also displays "Authenication Failed"
Im not sure what else to try

How to connect a 2.6 mongo shell to a 2.4.9 mongod?

Environment
Linux Mint 17.1
localhost
Default MongoDB port 27017
No username or password needed to connect from script.
Background
I installed MongoDB with:
apt-get install mongodb-10gen=2.4.9
I then 'pinned' the package so that no updates would be applied to it:
echo "mongodb-10gen hold" | sudo dpkg --set-selections
Desired Behaviour
I want to upgrade to the latest version of MongoDB and am looking at the official guide for this process:
http://docs.mongodb.org/manual/release-notes/2.6-upgrade
Early on it states:
To begin the upgrade procedure, connect a 2.6 mongo shell to your MongoDB 2.4 mongos or mongod and run the db.upgradeCheckAllDBs() to check your data set for compatibility.
Question
How do I connect a 2.6 mongo shell to a 2.4.9 mongod?
I would guess that I somehow need to just install the 2.6 mongo shell and run it but:
I don't know how to do that and
I don't want to break anything.
I've done a mongodump of all database so have a backup.
I made an attempt to install mongo 2.6 individually but that caused the other packages to be marked for removal. I ended up just uninstalling the old packages and re-installing the new ones and include the process here for reference.
Some of the steps below didn't work, but i've included them and their results as documentation of what was tried. I had previously done a mongodump of all databases so had a backup.
The end result is that everything currently seems to be 'working' apart from the admin database restore.
01. Shut down mongod
mongo
use admin
db.shutdownServer()
from: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
02. Removed the 'pinned package' state of mongodb-10gen with:
echo "mongodb-10gen install" | sudo dpkg --set-selections
from: https://help.ubuntu.com/community/PinningHowto
03. I then tried to install the latest mongo with:
sudo apt-get install -y mongodb-org-shell
from: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
04. The shell version seemed to be updated:
mongo --version
MongoDB shell version: 2.6.6
05. But then I couldn't connect with mongo:
mongo
connecting to: test
2015-01-04T00:08:50.482+1000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-01-04T00:08:50.483+1000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
or mongod:
mongod
The program 'mongod' is currently not installed. You can install it by typing:
sudo apt-get install mongodb-server
06. I ran the following to see the history of apt-get installs/removals:
less /var/log/apt/history.log
and got:
Start-Date: 2015-01-04 00:02:08
Commandline: apt-get install -y mongodb-org-shell
Install: mongodb-org-shell:amd64 (2.6.6)
Remove: mongodb-10gen:amd64 (2.4.9)
End-Date: 2015-01-04 00:02:21
07. I ran:
dpkg --get-selections
and saw:
mongodb-10gen deinstall
I think 'deinstall' means it is marked for removal.
08. I decided to remove all mongodb-10gen packages with:
sudo apt-get purge mongodb-10gen
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
gir1.2-clutter-gst-2.0 gir1.2-ges-1.0 gstreamer1.0-gnonlin libav-tools
libavdevice53 libavfilter3 libavresample1 libges-1.0-0 libgoocanvas-common
libgoocanvas3 libmlt++3 libmlt-data libmlt6 libqjson0 libquicktime2
libsoprano4 melt python-dateutil python-gst-1.0 python-matplotlib
python-matplotlib-data python-mlt python-pygoocanvas python-pyparsing
python-tz python3-bs4 python3-markdown shared-desktop-ontologies
soprano-daemon wkhtmltopdf
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
mongodb-10gen*
0 to upgrade, 0 to newly install, 1 to remove and 3 not to upgrade.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Y
(Reading database ... 246460 files and directories currently installed.)
Removing mongodb-10gen (2.4.9) ...
Purging configuration files for mongodb-10gen (2.4.9) ...
dpkg: warning: while removing mongodb-10gen, directory '/var/lib/mongodb' not empty so not removed
from: https://askubuntu.com/a/147177
09. I made a backup of the directory that could not be removed ie /var/lib/mongodb:
sudo cp -avr /var/lib/mongodb/ /home/
10. And then removed it.
cd /var/lib/
sudo rm -rf mongodb/
11. I searched to see if any mongodb-10gen packages were remaining:
dpkg --get-selections | grep "mongodb-10gen"
which returned nothing.
12. I installed mongodb-org at version 2.6.6 through Synaptic Package Manager.
13. I checked all mongodb packages were at the same version:
mongodump --version
mongorestore --version
mongo --version
mongod --version
mongos --version
# all returned 2.6.6
14. I then did a mongorestore with each database dump eg:
mongorestore --db dname_01 /path/to/dump/dbname_01/
mongorestore --db dname_02 /path/to/dump/dbname_02/
It seems to have worked on all databases but fails on the admin database:
assertion: 17415 Cannot restore users with schema version 1 to a system with server version 2.5.4 or greater
And the users database threw some anomalies eg:
Restoring to users.pending_registrations without dropping. Restored data will be inserted without raising errors; check your server log
Restoring to users.roles without dropping. Restored data will be inserted without raising errors; check your server log
Restoring to users.users without dropping. Restored data will be inserted without raising errors; check your server log
15. I ran db.upgradeCheckAllDBs():
mongo
use admin
db.upgradeCheckAllDBs()
Checking database local
Checking collection local.startup_log
Checking collection local.system.indexes
Checking database dname_01
...
Checking database admin
Everything is ready for the upgrade!
true
from: http://docs.mongodb.org/manual/release-notes/2.6-upgrade/#preparedness
I know you have managed to solve your question, but the following link helped me and I thought I could post it here for future reference and in case somebody else finds it hard upgrading mongodb:
http://blog.lecstor.com/mongodb-upgrade-24-to-26-in-debian
EDIT: A more appropriate answer, quoting the link above:
You have to download the tar version of MongoDB and run the shell straight from there:
$ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
$ tar -zxvf mongodb-linux-x86_64-2.6.1.tgz
$ ./mongodb-linux-x86_64-2.6.1/bin/mongo
To run the check, you also need to be using the admin database, so..
>use admin
switched to db admin
>db.upgradeCheckAllDBs()
Checking database mydb1
Checking collection mydb1.coll1
Checking collection mydb1.coll2
Checking database mydb2
Checking collection mydb2.coll1
Checking collection mydb2.coll2
Everything is ready for the upgrade!
true

Errors with mongodb-org packages on debian wheezy dpkg

I have a functional installation of mongo 2.6.6 running on my debian wheezy 7.7 server. I can run mongo and interact with the databases and collections within. It seems to operate without a problem. But every time I run a software update via:
sudo apt-get update
sudo apt-get upgrade
I get the following output:
Setting up mongodb-org-server (2.6.6) ...
[FAIL] Starting database: mongod failed!
invoke-rc.d: initscript mongod, action "start" failed.
dpkg: error processing mongodb-org-server (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mongodb-org:
mongodb-org depends on mongodb-org-server; however:
Package mongodb-org-server is not configured yet.
dpkg: error processing mongodb-org (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
mongodb-org-server
mongodb-org
E: Sub-process /usr/bin/dpkg returned an error code (1)
Searching for solutions to resolve this issue led me to service mongod start on debian doesnt work. I exported those environment variables and retried, but the errors persist. A bit more information:
...:~$ mongod --version
db version v2.6.6
2014-12-21T10:55:55.685-0600 git version: 608e8bc319627693b04cc7da29ecc300a5f45a1f
...:~$ mongodb --version
bash: mongodb: command not found
...:~$ sudo service mongod start
[FAIL] Starting database: mongod failed!
...:~$ sudo service mongod stop
[ ok ] Stopping database: mongod apparently not running.
...:~$ sudo service mongodb start
[ ok ] Starting database: mongodb apparently already running.
...:~$ sudo service mongodb stop
[ ok ] Stopping database: mongodb.
Unfortunately, I can't address whether the answer at service mongod start on debian doesnt work addressed the issue or if it was simply my stopping the server first.
After stopping both the mongod and mongodb services, then updating and upgrading, things went fine with no errors. The one thing I noticed was that I was running the "mongodb" service, but not the "mongod" service when I got the errors. After a successful update/upgrade, apt-get started the "mongod" service.
So, I'd recommend that if you experience this error, manually stop your databases then let the updater have its way with them. Mine are now working fine.