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

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

Related

Postgresql user "postgres" requires password in order to create db

I am running centOS 7 and trying to create a postgresql database
I entered to following to install and initiate database
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
sudo yum install postgresql11
sudo yum install postgresql11-server
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl enable postgresql-11
sudo systemctl start postgresql-11
so after this i try to create a database by entering
sudo createdb mydb
receive:
createdb: could not connect to database template1: FATAL: role "root" does not exist
so now i realize i need to be on the postgre user
and cannot create a db with this command:
sudo -u postgres createdb mydb
Recieve:
could not change directory to "/home/<user>": Permission denied
I am able to get the postgre prompt by entering the following
sudo -u postgres -i
psql
but when i enter sudo -u postgres -1 i get a new bash prompt -bash-4.2$
when i try to create a database in this prompt with sudo createdb mydb it asks for a password for postgres and can't go on from there,
what is this password? i read that by default it shouldn't
Did you try
sudo -i -u postgres
psql CREATE DATABASE yourbase;
\c yourbase ?

Unable to access postgres running inside docker container using psql command on terminal

I have postgres running inside docker container and I am able to access the postgres database using the below steps -
docker exec -it {container-id} bash
psql -U test postsdb
and I am in -
postsdb #
Also have installed kitematic and able to verify that docker pusblished IP:PORT is localhost:5432
but my app is not able to connect to postgres and giving the error -
SequelizeConnectionError: role "coder" does not exist
to debug this i tried connected to db using the postgres url from command line and what I saw strange is, it's also giving the same error
the command I used which is configured in my app as well is -
psql postgres://test:password#localhost:5432/postsdb

Unable to connect to server: postgresql on ubuntu in windows subsystem for 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

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/

Running Yesod in Cloud9

These are the steps I used to run a Yesod scaffold in Cloud9. The whole process took a few hours and I had to upgrade memory and disk (do this before proceeding):
Installing Stack
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 575159689BEFB442
(Ubuntu 14.04 (amd64)):
echo 'deb http://download.fpcomplete.com/ubuntu trusty main'|sudo tee /etc/apt/sources.list.d/fpco.list
sudo apt-get update && sudo apt-get install stack -y
Status: running $ stack from the command line works as expected
Yesod Template Quickstart
Create a new scaffolded site:
stack new yesodOnC9 yesod-postgres && cd yesodOnC9
Install the yesod command line tool:
stack build yesod-bin cabal-install --install-ghc
Build libraries:
stack build
Create PostgreSQL Database in C9
Start the PostgreSQL service
$ sudo service postgresql start
Connect to the service
$ sudo sudo -u postgres psql
Create a PostgreSQL database (from inside psql, at last step)
postgres=# CREATE DATABASE "yesodDB";
Create a test PostgreSQL database
postgres=# CREATE DATABASE "yesodDB_test"
Set Password for Postgres User
postgres-# \password postgres
Enter new password: MYPASSWORD
Result:
user: postgres
password: MYPASSWORD
Configure Yesod to Database
Open config/settings.yml
Change database user to:
user: "_env:PGUSER:postgres"
Change database password to:
password: "_env:PGPASS:MYPASSWORD"
Change database database to:
database: "_env:PGDATABASE:yesodDB"
Close settings.yml and open test-settings.yml
Change database database to:
database: yesodDB_test
Launch devel server:
stack exec -- yesod devel -b $IP -p $PORT
Result: Successful, Running Scaffold
If you leave your workspace, you will have to restart the PostgreSQL service with: $ sudo service postgresql start when you return.
Did you configure Postgres to accept TCP connections as indicated by the error message? Your installation of Yesod seems ok, but Yesod reads the DB to make a migration at start time so it needs a connection to your DB.

Resources