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

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 ?

Related

Connecting EC2 Amazon Linux2 to RDS PostgreSQL

I have an EC2 Amazon Linux2 running, and I want to access to RDS PostgreSQL databse from EC2.
I have finished adding EC2's security group ID to RDS's security group inbound.
I also successfully connected to RDS from my local PC.
I was looking for a way (or cli command) to connect to RDS from EC2 Amazon Linux.
Similary way for MySQL is:
sudo yum install mysql
mysql -u {username} -p -h {hostname}
I want to do the same with PostgreSQL, but could not find how to do so.
If there's a way I can follow through, please let me know.
Thanks!
why don't you use docker for that?
The easiest and fastest way that comes into my head is to do something like that
First, install docker
$ curl -L get.docker.com | sudo bash
$ sudo usermod -a -G docker $(whoami)
... you need to logout & login!
Then run docker container
$ docker run --rm -it postgres psql -h [your_RDS_host] -U [username] -W [database_name]
And you should be fine 😊

Postgresql: Connection refused Is the server running on host "127.0.01" (127.0.0.1) and accepting TCP/IP connections on port 5432?

I am a student learning Postgresql and I am having a consistent newbie error / mistake.
After a fresh install of postgres, am a able to make a new database, create tables, etc on a db on 127.0.0.1. Everything works fine until I restart my machine and try to relogin into my database. I get the error above in the picture.
I installed with the following commands:
echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" | sudo tee -a /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
apt-get update
apt-get install postgresql-12
apt-get install pgadmin4
chmod -R a+wrx /var/lib/postgresql
sudo -u postgres psql
ALTER USER postgres PASSWORD 'setnewPassword';
What else did I need to configure? Why do I get locked out after a restart? Any ideas? I am totally stuck...
Probably postgres service is stopped. You can check
sudo systemctl status postgresql
If it's off you can start it
sudo systemctl start postgresql
To make it permanent you can set it to auto start
sudo systemctl enable postgresql

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/

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