Unable to connect to server: postgresql on ubuntu in windows subsystem for linux - linux

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

Related

Can't run mongodb from wsl ubuntu

I've got problem with running mongodb on wsl ubuntu.
During using powershell everything works fine. I type node db.js and its working. After switching terminal to ubuntu and run the same command i get an error: "MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017".
Any idea how to resolve this problem?
Try to check mongod service status via cli
use service mongod status to check
If it's not active then try to activate
use this sudo service mongod start
If mongod service is not found then try to install the mongodb

Is there any way migrate postgresql db without pg_dump?

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>

PostgreSQL 9.4.10 - CREATE DATABASE throws ERROR: permission denied to create database

Postgres version: PostgreSQL 9.4.10 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit
Postgres server is installed using Vagrant with user account created at the time the VM was provisioned.
Steps I did to login and use psql command:
ssh to the server
sudo su - postgres
PGUSER=username PGPASSWORD=password psql -h localhost myapp
Than I issue the command in psql:
myapp=> CREATE DATABASE myDB;
ERROR: permission denied to create database
myapp=>
Can anyone tell me what do I miss? thanks

On Postgres-XC start getting sudo: unknown user: postgres sudo: unable to initialize policy plugin?

Installed Postgres-XC
$>sudo apt-get install postgres-xc
then
$ postgres -V
postgres (PostgreSQL) 9.2.4
after this I tried to start the Postgres server using following methods.
method 1
$>sudo postgres --coordinator -D DN2
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.
method2
$ sudo -i -u postgres
sudo: unknown user: postgres
sudo: unable to initialize policy plugin
and installed pgadmin3 also from there I want to connect Postgres server .
what is the correct way to start the Postgres-XC server?
Is the above procedure correct? if yes what is wrong with it?
To install Postgres's, the best way to is using enterpriseDB.
To see some downloader installer section from the below URL.
https://www.postgresql.org/download/linux/ubuntu/
To download the Postgres
http://www.enterprisedb.com/products-services-training/pgdownload#linux
To install the Postgres
http://tutorialforlinux.com/2014/02/20/how-to-install-latest-postgresql-9-x-on-linux-mint-16-petra-3264bit-linux-easy-guide/

postgresql commands not being executed

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.

Resources