Setting up PostgreSQL, could not connect to database postgres - file

I will create a django app on Debian 7 with postgreSQL 9.2.
I created a droplet in digital ocean. I updated and upgraded the system.
I used the following command
sudo aptitude install postgresql postgresql-contrib
to install postgresql.
When I changed user to postgres and I wanted to create a new db user with createuser -P
I filled all the fields it wanted but it came up with this error:
createuser: 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"?
I tried same process a few times with new droplets in Ubuntu 12.04 and Debian 7.
What should I do?
I want to use Debian 7, so I prefer solutions with Debian.
I am new at this stuff so be explanatory please.
Thanks.

I figured it out with fixing locale problem and reinstall PostgreSQL
First:
http://perlgeek.de/en/article/set-up-a-clean-utf8-environment
Second:
How to thoroughly purge and reinstall postgresql on ubuntu?
Set up the locale and make a clean installation for postgreSQL.
Thanks!

Related

Accessing existing windows postgresql database in WSL

I already have postgresql installed (psql (PostgreSQL) 13.4) and the local server set-up on my windows machine (along with pgAdmin4), and already have some databases in it.
I've recently installed WSL and planning on using it instead of windows+bash going forward. Hence I'm installing postgresql 13 for WSL. I follow https://pgdash.io/blog/postgres-13-getting-started.html for the installation:
# add the repository
> sudo tee /etc/apt/sources.list.d/pgdg.list <<END
> deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main
> END
# get the signing key and import it
> wget https://www.postgresql.org/media/keys/ACCC4CF8.asc sudo apt-key add
> ACCC4CF8.asc
# fetch the metadata from the new repo
> sudo apt-get update
> sudo apt-get install -y postgresql-13
It installed postgres with psql --version = psql (PostgreSQL) 13.4 (Ubuntu 13.4-1.pgdg20.04+1)
Then I start the service with
> sudo service postgresql start
> sudo -u postgres psql
My questions are:
When I check the list of databases I have using \l, I can't see my existing postgres database that I have in my windows machine, why? and how do I connect/import it to the wsl?
How do I make the WSL database/server appears in my existing pgAdmin4 GUI? I have already a server for my windows machine (localhost, port 5432). How can I add database from the WSL server, since it has the same settings? For example, I tried creating new database via WSL psql command line CREATE DATABASE ubuntu;, and the new database appears in the WSL postgres list in terminal, but the pgAdmin GUI only shows database from my windows server. How do I sync both databases in windows and WSL and show them both in pgAdmin?
database list in windows (from pgAdmin4)
database list in WSL
Thanks for the help

how to get database back while xampp is not working

I have created a database in MySQL using XAMPP But In Some How My XAMPP Server is Not Working Now I am trying to Get My data Back
It's in
xampp\mysql\data
folder. Or you can export the database in PHPmyadmin.
If you use Linux, you can install mysql-client and mysql-server:
sudo apt-get install mysql-client
sudo apt-get install mysql-server
and then access to phpMyAdmin with navigate to where you extract mysql. Then run this command:
php -S localhost:80
If you use windows, you can use an alternative software instead. I think Laragon is a good alternative software.

postgreSQL error initdb: command not found

i was installing postgresql on ubuntu using linuxbrew:
brew install postgresql
it seems to work fine but after that because i was installing PostgreSQL for the first time i tried creating a database:
initdb /usr/local/var/postgres -E utf8
but it returned as:
initdb: command not found
i tried running the command with sudo but that doesn't helped
run locate initdb it should give you the list to chose. smth like:
MacBook-Air:~ vao$ locate initdb
/usr/local/Cellar/postgresql/9.5.3/bin/initdb
/usr/local/Cellar/postgresql/9.5.3/share/doc/postgresql/html/app-initdb.html
/usr/local/Cellar/postgresql/9.5.3/share/man/man1/initdb.1
/usr/local/Cellar/postgresql/9.6.1/bin/initdb
/usr/local/Cellar/postgresql/9.6.1/share/doc/postgresql/html/app-initdb.html
/usr/local/Cellar/postgresql/9.6.1/share/man/man1/initdb.1
/usr/local/bin/initdb
/usr/local/share/man/man1/initdb.1
So in my case I want to run
/usr/local/Cellar/postgresql/9.6.1/bin/initdb
If you don't have mlocate installed, either install it or use
sudo find / -name initdb
There's a good answer to a similar question on SuperUser.
In short:
Postgres groups databases into "clusters", each of which is a named collection of databases sharing a configuration and data location, and running on a single server instance with its own TCP port.
If you only want a single instance of Postgres, the installation includes a cluster named "main", so you don't need to run initdb to create one.
If you do need multiple clusters, then the Postgres packages for Debian and Ubuntu provide a different command pg_createcluster to be used instead of initdb, with the latter not included in PATH so as to discourage end users from using it directly.
And if you're just trying to create a database, not a database cluster, use the createdb command instead.
I had the same problem and found the answer here.
Ubuntu path is
/usr/lib/postgresql/9.6/bin/initdb
Edit: Sorry, Ahmed asked about linuxbrew, I'm talking about Ubuntu.
I Hope this answer helps somebody.
I had a similar issue caused by the brew install postgresql not properly linking postgres. The solve for me was to run:
brew link --overwrite postgresql
you can add the PATH to run from any location
sudo nano ~/.profile
inside nano go to the end and add the following
# set PATH so it includes user's private bin if it exists
if [ -d "/usr/lib/postgresql/14/bin/" ] ; then
PATH="/usr/lib/postgresql/14/bin/:$PATH"
fi
and configure the alternative
sudo update-alternatives --install /usr/bin/initdb initdb /usr/lib/postgresql/14/bin/initdb 1

How to install mssql in ubuntu 14.04

I want to install mssql with 2008/2012.Please suggest proper doc or steps to install.I have try to instaall from https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-setup-ubuntu but it give me follwoing error -
/opt/mssql/bin/sqlservr: /usr/lib/x86_64-linux-gnu/libsss_nss_idmap.so.0: no version information available (required by /opt/mssql/bin/sqlservr)
Starting Microsoft SQL Server...
sudo: systemctl: command not found
Error starting Microsoft SQL Server.
while run command -
sudo /opt/mssql/bin/mssql-conf setup
you can't install mssql in ubuntu 14.04..Docs clearly state supported versions
SQL Server vNext CTP 2.0 is supported on the following platforms:
Just to add ,I thought installing docker would support versions less than 16,but from docker file we could see below
Base OS layer: Latest Ubuntu LTS.
FROM ubuntu:16.04
which means it needs ubuntu:16.04 versions to be present
For a workaround, you can use run a Docker container (microsoft/mssql-server-linux), e.g.
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrongPassword!" -p 1433:1433 microsoft/mssql-server-linux
Then connect to localhost:1433 with your SQL client.
It is not possible to instal sql server 2008 or 2012 on any non window platform.
This feature came with 2016 or 2017.
https://www.microsoft.com/en-us/sql-server/sql-server-2017
You can't because You must have 16.04+ Ubuntu version to install MSSQL according to documentation.

Not allowed do anything in PostgreSQL

I've seen plenty of answers across the internet saying that to combat the
psql:FATAL: role <username> does not exist
one must use the createuser command, but about a dozen different attempts with that command have only yielded a similar error message.
I've installed PostgreSQL using Ubuntu 15.04's sudo apt-get install postgresql, but PostgreSQL permits to do absolutely nothing.
Do I need to install some dependencies or something?
Try doing these actions as the postgres user:
$ sudo -u postgres -i
The PostgreSQL installation makes a postgres user which runs the PostgreSQL service. It is essentially the superuser of your database. In most cases, you don't know the password for this user but any superuser of a system can log in to other accounts.

Resources