Before I have used windows and git bash, Postgresql (13.1) has been installed. The path has been added:
And it worked well.
Later, I have to use Ubuntu (Windows Subsystem), then I use below command to install postgrel in Ubuntu
sudo apt-get install postgresql
It seems below version has been installed:
psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)
But when running in Ubuntu:
psql
shows error:
psql: error: 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"?
Use echo $PATH to check, below two paths have been added:
/mnt/c/Program Files/PostgreSQL/13/lib:/mnt/c/Program Files/PostgreSQL/13/bin
What I can see is that Ubuntu has installed Postgrel 12.6, should this path also be added to the system path? In fact, I couldn't figure out where Postgrel 12.6 being added. And this error is really caused by the path or other reason?
Have tried many kinds of methods. In the end, the below trial works:
sudo apt-get remove postgresql
Result:
[sudo] password for user:
Reading package lists... Done Building dependency tree
Reading state information... Done
Package 'postgresql' is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
sudo apt update
Result:
Building dependency tree
Reading state information... Done
21 packages can be upgraded. Run 'apt list --upgradable' to see them.
sudo apt install postgresql postgrsel-contrib
Result:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package postgrsel-contrib
psql --version
psql (PostgreSQL) 12.6 (Ubuntu 12.6-0ubuntu0.20.04.1)
sudo service postgrel start
postgrel: unrecognized service
sudo apt-get install postgresql postgresql-client
Result:
Success. You can now start the database server using:
pg_ctlcluster 12 main start
sudo service postgresql start
Now it shows:
starting postgresql 12 database (or similar sentence)
But no prompt up windows
\q to exit
sudo passwd postgres
You will get a prompt to set password
su - postgres
Now it works:
Password:
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 4.4.0-18362-Microsoft x86_64)
postgres=#
It seems that
step 7 helps to get the server running,
step 8 set the password to postgrel,
step 9 gives another way to start postgres service when sudo command doesn't work.
These are all of my trials. You might skip some steps when you run it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.