postgres dblink_connect ERROR: could not establish connection - postgresql

I am trying to connect to another server using pgadmin3. This is what I am doing:
CREATE EXTENSION dblink;
select postal.* from dblink('host=<name>.us-west-2.rds.amazonaws.com
user=postgres
password=postgres
dbname=name', 'select * from xwg201703.gc_bgr_postcodes')
AS postal(country varchar(3),
postalcode varchar(4),
town_bul varchar(60),
town_bun varchar(60),
locality_bul varchar(60),
locality_bun varchar(60))
limit 1;
The error I get:
ERROR: could not establish connection
DETAIL: could not connect to server: Connection timed out
Is the server running on host ".amazonaws.com" (...) and accepting
TCP/IP connections on port 5432?
Any input would be appreciated.

you cant use postgres as username on RDS
before creating dblink, check if you can connect at all. eg:
psql -h host=<name>.us-west-2.rds.amazonaws.com -U username -d db_name

Related

PQconnectdb set search_path (schema) while connecting

How do I specify the search_path while connecting to my postgres db using PQconnectdb? I want to set the search_path to my_schema. I'm currently using the following connection command:
PQconnectdb("host=localhost user=my_user password=my_password port=5432 dbname=my_db")
You could add the following to your connection info:
options='-csearch_path=my_schema'
So, it would become:
PQconnectdb("host=localhost user=my_user password=my_password port=5432 dbname=my_db options='-csearch_path=my_schema'")
Reference:
https://www.postgresql.org/message-id/D960CB61B694CF459DCFB4B0128514C20886AD46#exadv11.host.magwien.gv.at

Postgresql connection with gorm dial error cannot assign requested address

I'm trying to use the new gorm v2 implementation with Postgresql (I use Docker for the Golang app and for Postgres). I tried to do it as shown in the gorm documentation.
That gave me the following error:
web_1 | 2020/09/19 19:25:57 /go/src/caiqueservice/main.go:36 failed
to connect to host=/tmp user=admin database=caique: dial error (dial
unix /tmp/.s.PGSQL.5432: connect: no such file or directory)
So since the documentation didn't specify host, but the error message set that to /tmp I set that value.
dsn := fmt.Sprintf("host=%v user=%v password=%v dbname=%v port=%v sslmode=disable",
os.Getenv("DB_HOST"),
os.Getenv("DB_USERNAME"),
os.Getenv("DB_PASSWORD"),
os.Getenv("DB_DATABASE"),
os.Getenv("DB_PORT"),
)
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
.env
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=caique
DB_USERNAME=admin
DB_PASSWORD=password
Doing so gives me the following error message:
web_1 | 2020/09/19 19:36:47 /go/src/caiqueservice/main.go:36 failed
to connect to host=localhost user=admin database=caique: dial error
(dial tcp [::1]:5432: connect: cannot assign requested address)
The postgres db is reachable by pgadmin.
I don't know what to do next and help would be very much appreciated.
Inside a container, localhost refers to the container itself, not to the host machine. If you are using docker-compose, you should be able to connect to the postgres container (from the app container) using the postgres container name as the host name. If you are running both containers separately, you will need to connect them to the same docker network or link them.

PGBouncer : Cant connect on the right db

I'm actually facing an issue. I've installed pgbouncer on a production server, on which i've a Odoo instance and postgresql as well.
Perhaps :
In my logs, i'm having this :
2018-09-10 16:39:16.389 10123 WARNING C-0x1eb5478:
(nodb)/(nouser)#unix(18272):6432 pooler error: no such database: postgres
2018-09-10 16:39:16.389 10123 LOG C-0x1eb5478: (nodb)/(nouser)#unix(18272):6432 login failed: db=postgres user=oerppreprod
Here is the actual conf of pgbouncer :
pgbouncer_archive = host=127.0.0.1 port=5432 dbname=archive
admin_users = postgres
ignore_startup_parameters = extra_float_digits
With aswell, the default config (i've only added/edited this).
Why is he trying to connect on the postgres database ?
When i go back on the previous conf (without PGBouncer, just swapping from port 6432 to 5432), everything is working ....
Any idea ?
Thanks in advance !
I had the same issue, and in my situation. Maybe it will be usefull to somebody:
I have solved this by a few steps:
At the beginning of every request - your Framework or PDO (or else) running the initial query to check if database you asking is exists in the postgres data to process you request.
I have replaced the part of line "user=project_user password=mytestpassword" from the database section of pgbouncer.ini file. As I tested, if you replace this part - then the pgbouncer will use your userlist.txt file (or your selected auth), in my case, it was the userlist.txt.
Added the line "postgres = host=127.0.0.1 port=5432 dbname=postgres"
[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgres
my_database = host=127.0.0.1 port=5432 dbname=my_database
My userlist.txt file looks like this (I am using auth_type = md5, so my password was in md5):
"my_user" "md5passwordandsoelse"
I have added my admin users to my pgbouncer.ini file:
admin_users = postgres, my_user
After all manipulations I advise you to check from which user u are running queries, by usin this simple query:
select current_user;
At the end, with this query you must to receive you selected username (in my case it was - my_user)
p.s. also I must to mention, that I was using 127.0.0.1 - because my pgbouncer is installed on the same server with postgres.

What should I do when system tables of PostgreSQL are damaged?

My computer shut down because of power failier. And an error occurred in the log after I restarted the database:
ERROR: invalid page header in block 27073 of relation base/263742/11768.
I got to know that damaged relation is 'pg_class' by executing the command:
oid2name -H 127.0.0.1 -p 5432 -U postgres -f 11768
From database "postgres":
Filenode Table Name
----------------------
11768 pg_class
So, what should I do to recover my database as soon as possible? Thank you.

Cannot Setup Instance of Greenplum Command Center Web Application on Greenplum Open Source Database with Centos 7 Cluster

I have Greenplum Open Source Database running on a 3-node Centos 7 cluster. The database is running and I am able to connect and run queries. Installation of Greenplum Command Center 2.0 works. When I try to configure an instance for the web appliance part using
gpcmdr --setup
I get the following error:
Creating instance schema in GPDB. Please wait ...
Failed to setup Command Center instance [myCustomInstance]:
Exception encountered while fetching GPDB version info Connection error for query select version();:
FATAL: Ident authentication failed for user "gpmon"
Here is my pg_hba.conf file for testing purposes. This still generates the above error even with the host all all ::1/128 trust
# IPv6 local connections:
local all gpadmin ident
host all gpadmin 127.0.0.1/28 trust
host all gpadmin 172.17.0.1/32 trust
host all gpadmin 192.168.65.90/32 trust
host all gpadmin 192.168.122.1/32 trust
host all gpadmin ::1/128 trust
host all gpadmin fe80::210:18ff:fe94:3768/128 trust
host all gpadmin fe80::42:11ff:fea9:f1df/128 trust
host all gpadmin fe80::b84c:8bff:fe4a:5ce2/128 trust
host all gpadmin fe80::419:d7ff:fe90:6c48/128 trust
host all gpadmin fe80::c0ff:81ff:feae:c1ec/128 trust
local replication gpadmin ident
host replication gpadmin samenet trust
local gpperfmon gpmon md5
host all gpmon 0.0.0.0/0 md5
host all gpmon ::1/128 md5
host all all ::1/128 trust
Added in host all gpmon ::1/128 md5 before last line. Restarted the database and reran gpcmdr --setup. Below are the log files
gpperfmon/logs
2016-03-14 20:37:19|:-LOG: sounds like you have just upgraded your database, creating newer tables
2016-03-14 20:37:19|:-WARNING: [gpmondb.c:55] failed to execut query 'BEGIN; CREATE TABLE public.log_alert_history (LIKE gp_toolkit.__gp_log_master_ext) DISTRIBUTED BY (logtime) PARTITION BY range (logtime)(START (date '2010-01-01') END (date '2010-02-01') EVERY (interval '1 month')); COMMIT;': ERROR: relation "gp_toolkit.__gp_log_master_ext" does not exist
2016-03-14 20:37:19|:-WARNING: [gpmondb.c:1695] gpdb error ERROR: current transaction is aborted, commands ignored until end of transaction block
query: SELECT encoding FROM pg_catalog.pg_database d WHERE d.datname = 'gpperfmon'
2016-03-14 20:37:19|:-WARNING: [gpmondb.c:1769] gpdb failed to get server encoding.
pg_logs/gpdb-2016-03-14_203718.csv
2016-03-14 20:39:15.586557 EDT,"gpmon","gpperfmon",p11521,th-217848000,"[local]",,2016-03-14 20:39:15 EDT,89956,con25,cmd1,seg-1,,dx64,x89956,sx1,"LOG","00000","statement: SELECT sess_id, current_query FROM pg_stat_activity;",,,,,,"SELECT sess_id, current_query FROM pg_stat_activity;",0,,"postgres.c",1553,
2016-03-14 20:39:19.595436 EDT,"gpmon","gpperfmon",p11574,th-217848000,"[local]",,2016-03-14 20:39:19 EDT,89958,con26,cmd1,seg-1,,dx65,x89958,sx1,"LOG","00000","statement: insert into system_history select * from _system_tail;",,,,,,"insert into system_history select * from _system_tail;",0,,"postgres.c",1553,
2016-03-14 20:39:19.628287 EDT,"gpmon","gpperfmon",p11580,th-217848000,"[local]",,2016-03-14 20:39:19 EDT,89958,con26,cmd2,seg-1,slice1,dx65,x89958,sx1,"LOG","00000","statement: insert into system_history select * from _system_tail;",,,,,,"insert into system_history select * from _system_tail;",0,,"postgres.c",1096,
2016-03-14 20:39:19.681179 EDT,"gpmon","gpperfmon",p11588,th-217848000,"[local]",,2016-03-14 20:39:19 EDT,89961,con28,cmd1,seg-1,,dx66,x89961,sx1,"LOG","00000","statement: insert into queries_history select * from _queries_tail;",,,,,,"insert into queries_history select * from _queries_tail;",0,,"postgres.c",1553,
2016-03-14 20:39:19.713717 EDT,"gpmon","gpperfmon",p11594,th-217848000,"[local]",,2016-03-14 20:39:19 EDT,89961,con28,cmd2,seg-1,slice1,dx66,x89961,sx1,"LOG","00000","statement: insert into queries_history select * from _queries_tail;",,,,,,"insert into queries_history select * from _queries_tail;",0,,"postgres.c",1096,
Seems like gp_toolkit.__gp_log_master_ext doesn't exists. This table is created when gpdb generate its schema. Would you please try
"\d gp_toolkit.__gp_log_master_ext" in gpdb and see if the table is normalized?