Postgres dblink: Getting "[2F003] ERROR: password is required Detail: Non-superusers must provide a password in the connection string." - postgresql

When I try to run the following query, I get the following error message, and so my dblink queries are failing. All the hosts, roles, network connections and usernames have been set up correctly, yet it is not working.
select abc from dblink(
'port=5439 host=some_dbhost.mycompany.com dbname=my_db username=my_user password=<...>',
'select 1 as x') as t1 (abc int);
[2F003] ERROR: password is required Detail: Non-superusers must provide a password in the connection string.
No, there IS a password. What's going on?

This error message is TOTALLY misleading.
The REAL error is that the username was incorrectly specified as username.
The correct form specified as user (while the db is specified as dbname, so annoying!)
The fix is:
select abc from dblink(
'port=5439 host=some_dbhost.mycompany.com dbname=my_db user=my_user password=<...>',
'select 1 as x') as t1 (abc int);
So the error probably should have read as one of:
argument user missing
unknown argument username specified
instead of this stay up until 3am screaming to the heavens thing.

Related

Does PG8000 or Postgres client-server protocol not support bind parameters in DDL statements?

I'm trying to create a new user with PG8000. This code works, but it puts passwords in the server logs, which is not desirable (I'm not concerned with SQL injection for this usecase):
with pg8000.dbapi.connect(**CONNECTION_INFO) as conn:
csr = conn.cursor()
csr.execute("create user example password 'password-123'")
conn.commit()
I can then select information about that user with a query that uses bind parameters:
with pg8000.dbapi.connect(**CONNECTION_INFO) as conn:
csr = conn.cursor()
csr.execute("select * from pg_user where usename = %s", ("example",))
result = csr.fetchall()
However, if I try to create my user with a bind parameter:
with pg8000.dbapi.connect(**CONNECTION_INFO) as conn:
csr = conn.cursor()
csr.execute("create user example password %s", ("password-123",))
conn.commit()
The request fails with this client-side error:
DatabaseError: {'S': 'ERROR', 'V': 'ERROR', 'C': '42601', 'M': 'syntax error at or near "$1"', 'P': '30', 'F': 'scan.l', 'L': '1145', 'R': 'scanner_yyerror'}
And this server-side error:
2022-08-26 12:30:02.029 UTC [205] LOG: statement: begin transaction
2022-08-26 12:30:02.029 UTC [205] ERROR: syntax error at or near "$1" at character 30
2022-08-26 12:30:02.029 UTC [205] STATEMENT: create user example password $1
The same thing happens if I use the PG8000 "native" interface.
If I switch to psycopg2, I am able to execute the create command as written with parameters, however the server log indicates that the client did the parameter replacement, and sent a literal SQL statement:
2022-08-26 12:30:55.317 UTC [206] LOG: statement: BEGIN
2022-08-26 12:30:55.317 UTC [206] LOG: statement: create user example2 password 'password-123'
2022-08-26 12:30:55.317 UTC [206] LOG: statement: COMMIT
It appears that Postgres as a whole does not support invoking DDL from prepared statements. I was unable to find any authoritative documentation on this: not in the page for PREPARE, not in the Overview of PostgreSQL Internals, and not in the description of the client-server protocol. It is, however, easy to demonstrate:
postgres=# prepare ddl_example ( varchar(255) ) as
postgres-# create user example password '$1';
ERROR: syntax error at or near "create"
LINE 2: create user example password '$1';
^
In some of the pages that turned up from Googling, people commented that DDL doesn't go through the planner, which is where bind variables are applied. This makes sense, and if someone has a reference to official Postgres docs that says so, please answer with that link.

data corrupted in postgres - right sibling's left-link doesn't match: block 9550 links to 12028 instead of expected 12027 in index "log_attach_id_idx"

I am new to Postgres and we are using it for tests reports, we had an issue with our environment that entered duplicate keys to one of the table and since then we are getting this message when trying to run migration scripts:
error: migration failed: right sibling's left-link doesn't match: block 9550 links to 12028 instead of expected 12027 in index "log_attach_id_idx" in line 0: UPDATE log SET project_id = (SELECT project_id FROM item_project WHERE item_project.item_id=log.item_id LIMIT 1); (details: pq: right sibling's left-link doesn't match: block 9550 links to 12028 instead of expected 12027 in index "log_attach_id_idx")
I tried to run pg_dump and got this error:
pg_dump: error: query was: SELECT pg_catalog.pg_get_viewdef('457544'::pg_catalog.oid) AS viewdef
pg_dumpall: error: pg_dump failed on database "reportportal", exiting
Can anyone help here?
Restore your backup, and research what parameters you changed and what you did to end up with data corruption in the first place.

PostgreSQL on Corda enterprise node throws relation errors

Running corda enterprise with PostgreSQL in docker container. I have followed the instruction in docs and have set database schema. On database start I see the following errors. Can anyone help what is going on there?
2018-10-11 06:57:57.491 UTC [1506] ERROR: relation "node_checkpoints" does not exist at character 22
2018-10-11 06:57:57.491 UTC [1506] STATEMENT: select count(*) from node_checkpoints
2018-10-11 06:58:22.440 UTC [1506] ERROR: relation "corda-schema.databasechangeloglock" does not exist at character 22
2018-10-11 06:58:22.440 UTC [1506] STATEMENT: select count(*) from "corda-schema".databasechangeloglock
It seems the database user name and schema name don't have the same value, ensure that correct default schema is set for the user by running as database administrator:
ALTER ROLE "[USER]" SET search_path = "[SCHEMA]";
Other possible issue is to mixing upper/lower case and other characters in schema name, could you ensure that schema name has all lower cases (e.g. corda-schema and not CORDA-SCHEMA or Corda-Schema).

Database Link ORA-01017: invalid username/password; logon denied

Please help with this database link error i have been struggling for 2 days, Btw, fix this with get my oracle stream works. Stream error: WAITING FOR INACTIVE DEQUEUERS". Checked problem comes from db-link, so here is the problem:
--user: sys
--environmentL appuat1
CREATE PUBLIC DATABASE LINK "ANAUAT0" USING 'anauat0
--user: STRMADMIN_FORM
--environmentL appuat1
CREATE DATABASE LINK ANAUAT0
CONNECT TO "STRMADMIN_FORM" IDENTIFIED BY "STRMADMIN_FORM"
USING 'anauat0';
--user: STRMADMIN_FORM
--environmentL appuat1
select * from STRMADMIN_FORM.Table#'anauat0;
ERROR:
ORA-01017: invalid username/password; logon denied
ORA-02063: preceding line from ANAUAT0
01017. 00000 - "invalid username/password; logon denied"
Question1: Given that username & password are correct, what is the problem?
--user: SYS
--environmentL appuat1
select * from STRMADMIN_FORM.Table#'anauat0;
ERROR:
ORA-28000: the account is locked
ORA-02063: preceding line from ANAUAT0
28000. 00000 - "the account is locked"
*Cause: The user has entered wrong password consequently for maximum
number of times specified by the user's profile parameter
FAILED_LOGIN_ATTEMPTS, or the DBA has locked the account
*Action: Wait for PASSWORD_LOCK_TIME or contact DBA
Question 2: Checked no account are locked, what is locked?
From the other way round can select table using opposit direction Db-link.
update: a trade of to prevent error is to use tns information :
CREATE DATABASE LINK "ANAUAT0"
CONNECT TO "STRMADMIN_ADM" IDENTIFIED BY "STRMADMIN_ADM"
USING '(DESCRIPTION=
(ADDRESS=
(PROTOCOL=TCP)
(HOST=xx.xx.xx.xxx)
(PORT=1521)
)
(CONNECT_DATA=
(SERVICE_NAME=anauat0)
)
)';
But using service name is what I want to do. Obviously service name is cause of problem (the service name is working fine)
Thanks!!
Somebody added a same name TNS on the server cause comflict.
Thanks!

error when trying to execute to sql

I'm using Mulestudio and am trying to insert into the Postgres database some data. I am modifying the log4j.properties file and below is how it looks like:
log4j.rootLogger = DEBUG, postgres
#
log4j.appender.postgres=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.postgres.layout=org.apache.log4j.PatternLayout
log4j.appender.postgres.driver=org.postgresql.Driver
log4j.appender.postgres.URL=jdbc:postgresql://127.0.0.1:5432/testing
log4j.appender.postgres.user=postgres
log4j.appender.postgres.password=pw
log4j.appender.postgres.sql=INSERT INTO LOGS VALUES ('%x', '%d{yyyy-MM-dd}','%C','%p','%m');
The error message that I get is
log4j:ERROR Failed to excute sql
org.postgresql.util.PSQLException: ERROR: syntax error at or near "edu"
'edu' is the first part of my project name (edu-stream-ucdnews). The instance of 'edu' only comes up in the title name and not in my data. I know that the error arises when I have the '%m' when I try to insert the data because when I change it to a hard-coded message like 'Hello', I don't get any error.
How do I solve this issue?
Are you sure your are connected to the database?
Try putting the fields name in your sql and lets check if we get a better error log:
log4j.appender.postgres.sql=INSERT INTO LOGS (field1, field2, ...) VALUES ('%x', '%d{yyyy-MM-dd}','%C','%p','%m');