No passwd entry for user 'postgres' error - postgresql

I'm trying to setup Postgres on Ubuntu 14.04 without success. After running
sudo apt-get install libpq-dev python-dev
and
sudo apt-get install postgresql postgresql-contrib
I've managed to install the packages successfully. However upon executing sudo su - postgres, I'm receiving the following error:
No passwd entry for user 'postgres'
It seems like the installation did not create the user postgres as it is not in the /etc/passwd file. Reinstalling the package does not resolve the issue. How can I add the required postgres user?

It sounds like you want the PostgreSQL server:
apt-get install postgresql-server
Also, you never need to use sudo su - postgres. Just:
sudo -u postgres -i
to get an interactive shell, or
sudo -u postgres psql
(or whatever) to run a command.

I've solved the issue by purging and re-installing the packages, i.e.
sudo apt-get --purge remove postgresql*
sudo apt-get install postgresql postgresql-contrib

Related

Installing MongoDB in WSL

I was trying to install MongoDB in WSL running Ubuntu 18.04 after seeing this documentation. But MongoDB says that:
IMPORTANTThe mongodb package provided by Ubuntu is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you have already installed the mongodb package on your Ubuntu system, you must first uninstall the mongodb package before proceeding with these instructions.
MongoDB also says that WSL doesn't support mongodb-org
WINDOWS SUBSYSTEM FOR LINUX (WSL) - UNSUPPORTEDMongoDB does not support the Windows Subsystem for Linux (WSL).
So, I installed mongod using sudo apt install mongodb and when I ran mongo it shows the error:
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-06-21T13:33:40.606+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017
Is there is a way to install the appropriate package and make it running?
I have come across this situation recently.
Even though MongoDB says that it is not supported in WSL, you can actually install it. So, I suggest you follow that steps given in MongoDB docs.
Note : If you have already installed mongodb please remove all those before you install mongodb-org since it may cause some issues during installation :
sudo dpkg --remove --force-remove-reinstreq mongo-tools
sudo dpkg --remove --force-remove-reinstreq mongodb-server-core
sudo apt-get --fix-broken install
For installing mongodb community edition, I have added the commands below:
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
Now, to get mongoDB running,
sudo nano /etc/init.d/mongod
and paste the contents in this link into the file and save it.
#give permissions
sudo chmod +x /etc/init.d/mongod
#start the service
sudo service mongod start
Now, you can run mongo to reach the database.
Hope it helps.
#bonyem's solution works if you try on Ubuntu 18.04 (and apparently in 19.10) but not in 20.04. WSL version should be 2 (please see this to update WSL).
You also need to "fake" the bash binary by following the steps mentioned in https://github.com/shayne/wsl2-hacks to make systemctl work.
I tried all the methods above but none of the methods worked. I came across Microsoft's official documentation and everything works like a charm.
https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-database#install-mongodb
This worked for me.
Run sudo apt install mongodb
Then after that installs run sudo service mongodb start
It will say * Starting database mongodb
And after that I can connect using mongo
Easiest way to bypass this issue is to run MongoDB on Windows. You'll still be able to connect from WSL2 over localhost.
For me, #bonyem's solution resulted in an error:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
I'm going to install Mongo 4.4. Many instructions were taken from #Lyubosumaz's directions here.
Get rid of all your Mongo PPAs.
~ ❯ sudo ls /etc/apt/sources.list.d
mongodb-org-4.4.list yarn.list
~ ❯ sudo rm -i /etc/apt/sources.list.d/mongodb-org-4.4.list
Remove all Mongo packages and bits and pieces.
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
sudo dpkg --remove --force-remove-reinstreq mongo-tools
sudo dpkg --remove --force-remove-reinstreq mongodb-org
sudo dpkg --remove --force-remove-reinstreq mongodb-org-server
sudo dpkg --remove --force-remove-reinstreq mongodb-server-core
sudo dpkg --remove --force-remove-reinstreq mongodb-org-mongos
sudo dpkg --remove --force-remove-reinstreq mongodb-org-shell
sudo dpkg --remove --force-remove-reinstreq mongodb-org-tools
sudo apt-get --fix-broken install
yes | sudo apt autoremove
Add new PPA and install Mongo 4.4.
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y mongodb-org
You'll get the same error from before. This is caused by mongodb-org package trying to use systemctl to start the DB after install (source). Notice that the same error is thrown when running the command manually.
~ ❯ sudo systemctl start mongod
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
However, running mongod should still work!
If you run into errors when running mongod, you might need to modify some permissions and create a data directory. I found the answer to these issues here, here, and here.
sudo chown $USER /tmp/mongodb-27017.sock
sudo mkdir -p /data/db
sudo chown -R $USER /data/db
I have tried some of the answers above, it did not work for me.
Then I followed a guide 1:
Update ubuntu packages
Install MongoDB on the command line
Set up your local database
Creating the folders and permissions
It worked in my case!

How to upgrade to PostgreSQL 11 for Ubuntu 18.04?

As the title suggests I want to upgrade my postgresql-10 to postgresql-11.
I'm using ubuntu-18.04.
You can follow this blog setup Postgresql-11 on Ubuntu. I found it easy and simple.
Add the PostgreSQL package repository on your Ubuntu machine
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main 11" | sudo tee /etc/apt/sources.list.d/pgsql.list
Add the GPG key of the PostgreSQL package repository:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Update APT and install postgresql-11
sudo apt update && sudo apt install postgresql-11
Upgrading Postgres to the latest version (currently 13), or to an intermediate version such as 11, should be done by running:
sudo apt install postgresql-common
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
This is documented on https://wiki.postgresql.org/wiki/Apt
This runs a bash script on your computer. See there if you wish to run the steps manually.
Once you have installed Postgres, the easiest way to upgrade on Ubuntu is with pg_upgradecluster.
Backup your data. You will dropping the database, so no games!
sudo -u postgres pg_dumpall > all.sql
Upgrade.
// Install latest Postgres. Use `postgresql-11` for v11 instead of `postgresql` for latest.
sudo apt-get install -y postgresql
// The install sets up a cluster, which needs then to be removed for the upgrade.
// Stop and remove the newly installed cluster. Use `11` instead of `13` for v11
sudo pg_dropcluster 13 main --stop
// Upgrade the db. Takes the OLD version and OLD schema as required arguments
sudo pg_upgradecluster 10 main
// Test. Once you are satisfied, remove OLD cluster.
sudo pg_dropcluster 10 main
Use this command:
sudo apt update && sudo apt install postgresql-11

Install pgAdmin on a remote server and configure without a desktop environment

I have installed PostgreSQL 9.6.1 on a remote Debian 8.1 minimal VM. I am attempting to install pgAdmin4 in server mode so that I am able to access remotely via the web. I have successfully installed pgAdmin4 within a python virtual environment, but an issue arises at one of the final steps of configuration:
Starting pgAdmin 4. Please navigate to http://localhost:5050 in your browser.
Since I do not have a desktop environment installed (nor do I intend on installing one), how can I complete configuration without using localhost? I have attempted to connect using the server's public IP (e.g. http://80.254.0.132:5050) but am not able to resolve.
I do not have a firewall at the VM or server/NAT level.
I have updated /etc/postgresql/9.6/main/pg_hba.conf and added host all all 0.0.0.0/0 md5 to the configuration.
I have updated /etc/postgresql/9.6/main/postgresql.conf and changed listen_addresses = '*'.
My full steps involved in post-Debian installation (sans new users) looks like the following:
# Initial update.
apt-get install sudo
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y
sudo apt-get install vim -y
# Postgres.
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
# Install PostgreSQL.
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib libpq-dev python-dev
# Set postgres password.
sudo -s
cd ~
sudo -u postgres psql postgres
\password postgres
# Allow remote connections.
sudo vim /etc/postgresql/9.6/main/pg_hba.conf
# host all all 0.0.0.0/0 md5
sudo vim /etc/postgresql/9.6/main/postgresql.conf
# listen_addresses = '*'
sudo service postgresql restart
# Python and pgAdmin.
sudo easy_install pip
sudo pip install virtualenvwrapper
# Create the virtual environment and install pgAdmin.
virtualenv pgadmin4
cd pgadmin4
source bin/activate
sudo apt-get install build-essential libssl-dev libffi-dev python-dev libgmp3-dev
sudo pip install cryptography pyopenssl ndg-httpsclient pyasn1
wget https://ftp.postgresql.org/pub/pgadmin3/pgadmin4/v1.1/pip/pgadmin4-1.1-py2-none-any.whl
pip install pgadmin4-1.1-py2-none-any.whl
cp ./lib/python2.7/site-packages/pgadmin4/config.py ./lib/python2.7/site-packages/pgadmin4/config_local.py
python ./lib/python2.7/site-packages/pgadmin4/pgAdmin4.py
By default pgAdmin4 runs on loopback adapter, to make it run on ethernet (eth0) you need to change some of configuration options.
You need to add below config options,
DEFAULT_SERVER = '0.0.0.0'
in config_local.py (in "pgAdmin4" folder).
If also want to change default port then also add
DEFAULT_SERVER_PORT = 8081
Now restart pgAdmin4, Now try accessing pgAdmin4 using IP address you mentioned(eg, http://80.254.0.132:8081), It should work.

Cannot use commands 'postgres' or 'pg_ctl'

I am on Unix. I have got postgresql-9.3 installed.
When I want to start the server using pg_ctl or postgres, the terminal gives me:
The program 'postgres' is currently not installed. You can install it by typing:
sudo apt-get install postgres-xc
Can't I start the server without this postgres-xc?
This must be remnants of the postgres-xc package you had installed previously.
Since you just installed postgresql-9.3 and don't seem to have any databases in use, yet, I suggest to completely purge all postgres packages.
sudo apt-get purge postgresql-9.2
sudo apt-get purge postgresql-xc
...
Until there's nothing left:
dpkg -l | grep postgres
Then start from scratch. Your instance of pg_ctl seems to belong to the package postgres-xc. This should be gone after you've uninstalled the package. Find out with one of these commands:
dpkg -S pg_ctl
dlocate pg_ctl
apt-file search pg_ctl
pg_ctlcluster is provided by the package postgresql-common.
pg_ctl is provided by the package postgresql-9.3.
More about starting Postgres in the manual.
It is possible you might be missing a few things.
Try:
sudo apt-get install postgresql-client and
sudo apt-get install postgresql postgresql-contrib
The message about installing xc is a dud, it's probably suggesting that based on what it scanned inside the xc repositories.
Here's a good reference to this problem and its solution:
https://dba.stackexchange.com/questions/72580/missing-the-pg-ctl-package-in-postgres-9-3-installation
Due to reasons a normal install of postgres will not place the postgres binary file in the path.
Adding the right directory to the path solves the problem (temporarily).
PATH=/usr/lib/postgresql/9.3/bin:$PATH
To make it permanent on my Ubuntu machine I added the line to /etc/environment this makes it work for all users.
The correct way to set the PATH is different for different systems, for more info see see:
How to permanently set $PATH on Linux?
You must install postgresql-client:
sudo install postgresql-client
Try to enter this command to the console:
sudo -u postgres psql

cannot find adminpack.sql in postgresql 9.1

I'm trying to get it installed and use in ubuntu. Was following this page to install the additional instrumentation packages.
Install Server Instrumentation for Postgresql 8.4
To install Server Instrumentation for Postgresql 8.4 you may use the command line and type:
sudo apt-get install postgresql-contrib
Run the adminpack.sql script, simply type:
sudo -u postgres psql < /usr/share/postgresql/8.4/contrib/adminpack.sql
But I couldn't find adminpack.sql in 9.1 version.
In PostgreSQL 9.1 and later, extensions can be installed via the CREATE EXTENSION command:
sudo -u postgres psql
CREATE EXTENSION "adminpack";
Try locate adminpack. But first, run updatedb to make sure the locate database is up to date.
sudo updatedb
locate adminpack
The output is:
/usr/lib/postgresql/9.1/lib/adminpack.so
/usr/share/postgresql/9.1/extension/adminpack--1.0.sql
/usr/share/postgresql/9.1/extension/adminpack.control
Looks like this is old and comments are closed, so I'm opening another answer.
ldalonzo's answer is correct once you have all the components, but I found I also had to run:
sudo apt-get install postgresql-contrib-9.1
Looks like the bare postgresql package doesn't include the additional modules.
Once you install postgresql-contrib using below command
sudo apt-get install postgresql-contrib
Adminpack is located in the below path
/usr/share/postgresql/9.1/extension/adminpack--1.0.sql
To load the adminpack use the below command
sudo su postgres -c psql < /usr/share/postgresql/9.1/extension/adminpack--1.0.sql
Then
sudo /etc/init.d/postgresql restart