Apache Airflow install Postgress as Backend DB - ERROR - postgresql

I am trying to install Postgres as a backend DB instead of Sqllite. I followed these steps but ran into an error. can someone help, please?
Steps followed:
activated virtual env.
installed postgreSQL
sudo apt-get install postgresql postgresql-contrib
created psql object with:
sudo -u postgres psql
4.create the user and database for the airflow
CREATE USER **** PASSWORD '****';
postgres=# CREATE DATABASE airflow;
postgres=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO newt;
updated postgresql.conf with listen_addresses= '*'
added pg_hba.conf with
host db-name user-name ip-address trust
updated airflow.cfg file with
sql_alchemy_conn = postgresql+psycopg2://user-name:password#localhost:5432/db-name
restarted airflow db.
airflow resetdb
After the 8th steps I got below error, what am i doing wrong here? any advise
Error message
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

After changing the pg_hba.conf and postgresql.conf you have to tell PostreSQL that a change has been made. You can do it by either restarting the database, e.g. on Ubuntu
$ sudo service postgresql restart
... or by executing the function pg_reload_conf
SELECT pg_reload_conf():
In case client and database are in different machines, make sure that there is no firewall between them messing things up.
Unrelated note: Also keep in mind that setting a connection to trust in the pg_hba.conf means that no password is required. For testing purposes more than legit but quite dangerous if forgotten in production ;)

Related

Connection to remote machine postgresql database

I am trying to connect to a VM ubuntu from my local computer. On the VM I have created a postgresql database. Then I followed all steps that I could find on several tutorial when it comes to allow access for remote connexion to the db:
add host all all 0.0.0.0/0 trust to the pg_hba.conf file
add listen_addresses = '*' to the postgresql.conf file
remove the firewall by executing sudo ufw allow 5432/tcp
restart postresql by executing sudo systemctl restart postgresql
By using the command psql and then \c gives You are now connected to database "postgres" as user "postgres".
I then create a password by executing ALTER USER postgres WITH PASSWORD 'password';
Then I use postico to connect locally. I want to connect with this same default superuser postgres for testing. I use the VM ip address as host, db name is postgres user postgres, password is password and port 5432 as mentioned above.
After trying to connect for a while with the message opening connection to server, the result is:
could not connect to server: Operation timed out
Is the server running on host "***.**.**.***" and accepting
TCP/IP connections on port 5432?
Any help please? I did all steps I could find on many tutorials but still failing to connect.

connect pgadmin3 to postgres runnng on server

** new to pgadmin and postgress **
my organization uses PostgreSQL on its server with ubuntu os, I try to connect it using pgadmin 3,
these are the stapes I have taken
changed pg_hba.conf using 'sudo nano /etc/postgresql/9.3/main/pg_hba.conf'
changed listen_addresses='*' in postgresql.conf file
sudo ufw allow 5432/tcp
but still, I am unable to connect I get this error from pg admin:
Server doesn't listen
The server doesn't accept connections: the connection library reports could not connect to server: Connection timed out Is the server running on host "103.72.131.155" and accepting TCP/IP connections on port 5432?
how can I fix it,
is there any website which can guide me step by step to connect pgadmin to PostgreSQL.

Cant access database from pgAdmin

I`m using postgresql database on my web server (ubuntu + nginx) and it works with backend app. I want to connect remotely using pgAdmin
but it always throw this error:
could not connect to server: Connection timed out(0x0000274C/10060)
Is the server running on host "ip" and accepting
TCP/IP connections on port 5432?
I already add to my pg_hba.conf this line:
host all all all password
and also add to postgresql.conf line:
listen_addresses = '*'
netstat -nlt does next result, and it`s enough in tutuorials i found, but still cant access my database
Found a solution, it works as well after this command:
sudo ufw allow 5432/tcp
Open file named pg_hba.conf
sudo vi pg_hba.conf
and add this line to that file
host all all 0.0.0.0/0 md5
It allows access to all databases for all users with an encrypted password
restart your server
sudo /etc/init.d/postgresql restart

Amazon EC2 and PostgreSQL: cannot connect due to time out error

I think I followed any possible guide before asking here.
I am trying to remotely connect to a PostgreSQL db installed on a EC2 Linux instance (Ubuntu server 18.04, free tier if it matters).
Here are all the steps I did before hitting a wall and begging for help.
I connected to my instance via SSH
I downloaded and installed postgres following this docs
I created a new used (umberto)
I created a new DB (wondermap)
I created a new OS user with the same name as in step 3 (umberto)
I connected to my new db with my new user from the server and everything woked fine
I edited /etc/postgresql/10/main/pg_hba.conf adding these lines:
host all all 0.0.0.0/0 md5
host all all ::/0 md5
I edited /etc/postgresql/10/main/postgresql.conf changing #listen_addresses = 'localhost' into listen_addresses = '*'
i restarted the postgres server with sudo service postgresql restart
I added a new Inbound rule in the instance security group like so:
TCP port:5432 source:0.0.0.0/0, ::/0
After all, I am trying to connect from my local mahine (either using pgadmin3 or psql) but I still receive a timeout error (host is hidden):
psql -h <PUBLIC-IP-OF-MY-INSTANCE> -U umberto -d wondermap
or even
psql -h <PUBLIC-IP-OF-MY-INSTANCE> -U postgres
psql: could not connect to server: Connection timed out
Is the server running on host "<PUBLIC-IP-OF-MY-INSTANCE>" and accepting
Doing SELECT version(); shows:
PostgreSQL 10.7 (Ubuntu 10.7-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0, 64-bit
What could be the problem?
Apparently, I stil had to unblock postgres port on server's firewall.
sudo ufw allow 5432/tcp
That did the trick!

postgres server running in local host, but postico, pgadmin can't access to it

I successfully installed postgres through homebrew, and i set it run automatically by doing
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
So, right now i can access to psql from my terminal (i use iterm2 + oh my zsh)
psql (9.6.1)
Type "help" for help.
ty2kim=#
The problem is, postgres management tools like postico, pgadmin cannot access to it
for postico, error message is
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5435?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5435?
which is weird because from my understanding, accessing to the database from terminal and management tools are basically the same if configured correctly
My pg_hba.conf and postgresql.conf are set as default (didn't make any changes there), but i tried doing
listen_addresses = 'localhost'
=>
listen_addresses = '*'
(restart server)
still didn't work
Please help!
Port 5435 is not standard for PostgreSQL. Are you sure PG is running on it? If you didn't change it in postgresql.conf it must be 5432. Please check it.
must check pg_hba.conf. If there doesn't have much restriction, you can put to end of this file by below line:
host all all all trust
After that, reload/restart instance.
Check if your PC is using firewall. If yes, please turn off it.