PostgresSQL: org.postgresql.util.PSQLException: ERROR: Unsupported startup parameter: search_path - postgresql

When I try to connect to the database on postgres via jdbc, I get the following error:
org.postgresql.util.PSQLException: ERROR: Unsupported startup parameter: search_path
This is how I create the connection:
val connection = DriverManager.getConnection(profile.connection + Option(profile.catalog).getOrElse("")+ "?currentSchema="+Option(profile.schema).getOrElse(""),
profile.user, profile.password)
I use scala and a custom version of postgres.

pgbauncer
In short, pgbouncer at least my version does not work with the search_path parameter, this discussion led me to this idea. There are two ways to fix this problem:
Change the pgbouncer config file by adding
IGNORE_STARTUP_PARAMETERS: search_path
Make a connection without using the currentSchema parameter in the connection string and create connection like this:
val connection =
DriverManager.getConnection(
profile.connection + Option(profile.catalog).getOrElse(""),
profile.user, profile.password)
Then he will choose the scheme according to the rule set, in search_path, they usually set something like "$user", public, in this case, when connecting, he first tries to choose the same scheme as the user name, and if he does not find such a scheme, he chooses public.

Related

How to connect a Firebird data base with Knime?

I need connect my Firebird data base (.IDB) in KNIME. I used Database Connector node, but I have this notice:
ERROR Database Connector 0:1 Execute failed: Could not create
connection to database: Invalid connection string
C:\Users\miPC\Desktop\DataBase1.IDB, reason: null or empty database
name in connection string
The error suggest that you have used the following connection string:
jdbc:firebirdsql://C:\Users\miPC\Desktop\DataBase1.IDB
That is incorrect as it is missing the host name. The correct URL would be:
jdbc:firebirdsql://localhost/C:\Users\miPC\Desktop\DataBase1.IDB
Please consult the Jaybird FAQ for valid URL formats.

SailsJS MongoDB Database connection error

I am new for SailsJS. I am trying to create database connection with mongo but it shows error like this
A hook (`orm`) failed to load!
error: Error: Consistency violation: A model (`sleep`) references a datastore which cannot be found (`mongo`).
If this model definition has an explicit `connection` property, check that it is spelled correctly.
If not, check your default `connection` (usually located in `config/models.js`).
Finally, check that this connection (`mongo`) is valid as per http://sailsjs.org/documentation/reference/configuration/sails-config-connections.
Your model is connecting to an invalid connection 'mongo'.
Check the connection either in you model 'Sleep' or in config/models.js

Specify `statement_timeout` in Postgresql with sqlalchemy?

The following statement_timeout option works on some Postgresql databases and on others, I get Unsupported startup parameter: options. Why?
Is this possibly a difference between Postgres 9.4 and 9.6? This works with the former servers and fails with the latter.
from sqlalchemy import create_engine
# As is: Unsupported startup parameter: options
db_engine = create_engine("postgresql://user:pw#host/database",
connect_args={"options": "-c statement_timeout=1000"})
with db_engine.connect() as db_connection:
print("got it")
Specifically, I get:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) ERROR: Unsupported startup parameter: options
You may have been connecting to those databases via PgBouncer.
If so, add ignore_startup_parameters = options to pgbouncer.ini under the [pgbouncer] section.
From https://www.pgbouncer.org/config.html#ignore_startup_parameters:
By default, PgBouncer allows only parameters it can keep track of in startup packets: client_encoding, datestyle, timezone and standard_conforming_strings. All others parameters will raise an error. To allow others parameters, they can be specified here, so that PgBouncer knows that they are handled by the admin and it can ignore them.
Default: empty
References:
https://github.com/pgbouncer/pgbouncer/issues/295
https://github.com/pgbouncer/pgbouncer/issues/496

Sail.js multiple connections on start

I've got an odd problem - on start of my sails app (which is connecting with postgres and deployed on heroku ) there are multiple connections (around 10) to database, and since it's free account, if I then try to launch app on localhost to test some new code I get an error "too many connections for a role". So does anyone know why there are so many connections to database and can I change it, to have only one connection per app?
EDIT:
Error creating a connection to Postgresql: error: too many connections for role
"xwoellnkvjcupt"
Error creating a connection to Postgresql: error: too many connections for role
"xwoellnkvjcupt"
error: Hook failed to load: orm (error: too many connections for role "xwoellnkv
jcupt")
error: Error encountered while loading Sails core!
error: error: too many connections for role "xwoellnkvjcupt"
at Connection.parseE (C:\Studia\szachman2\node_modules\sails-postgresql\node
_modules\pg\lib\connection.js:561:11)
at Connection.parseMessage (C:\Studia\szachman2\node_modules\sails-postgresq
l\node_modules\pg\lib\connection.js:390:17)
at null. (C:\Studia\szachman2\node_modules\sails-postgresql\node_
modules\pg\lib\connection.js:98:18)
at CleartextStream.EventEmitter.emit (events.js:95:17)
at CleartextStream. (_stream_readable.js:746:14)
at CleartextStream.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at _stream_readable.js:401:7
at process._tickDomainCallback (node.js:459:13)
this is an error I am getting often when trying to test some new code on localhost.
#jantar #sgress454 I just added a troubleshooting message in sails-postgresql to try and make this better. Here's what it says:
-> Maybe your poolSize configuration is set too high? e.g. If your Postgresql database only supports 20 concurrent connections, you should make sure you have your poolSize set as something < 20. The default poolSize is 10.
To override the default poolSize, specify a poolSize property on the relevant Postgresql "connection" config object. If you're using Sails, this is generally located in config/connections.js, or wherever your environment-specific database configuration is set.
-> Do you have multiple Sails instances sharing the same Postgresql database? Each Sails instance may use up to the configured poolSize # of connections. Assuming all of the Sails instances are just copies of one another (a reasonable best practice) we can calculate the actual # of Postgresql connections used (C) by multiplying the configured poolSize (P) by the number of Sails instances (N). If the actual number of connections (C) exceeds the total # of AVAILABLE connections to your Postgresql database (V), then you have problems. If this applies to you, try reducing your poolSize configuration. A reasonable poolSize setting would be V/N.
This is due to Sails's auto-migration feature which attempts to keep your models and database synced up. It's not intended to be used in production. You can turn auto-migration off on a single model by adding migrate: safe to the model definition:
module.exports = {
migrate: 'safe',
attributes: {...}
}
You can turn auto-migration off for all models by adding a model config, usually in your config/locals.js:
module.exports = {
model: {
migrate: 'safe'
},
environment: 'production',
...other local config...
}
A little update for the V1. Your adapter in config/datastore.js should look like this if you want to set a maximum size for the connection pool :
{
adapter: 'sails-postgresql',
url: 'yourconnectionurl',
max: 1 // This is the important part for poolSize, I set 1 because I don't want more than 1 connection ^^
}
If you want to know all infos you can set, look here : https://github.com/sailshq/machinepack-postgresql/blob/176413efeab90dc5099dc60718e8b520942ce3be/machines/create-manager.js , at line 162 :
// Basic:
'host', 'port', 'database', 'user', 'password', 'ssl',
// Advanced Client Config:
'application_name', 'fallback_application_name',
// General Pool Config:
'max', 'min', 'refreshIdle', 'idleTimeoutMillis',
// Advanced Pool Config:
// These should only be used if you know what you are doing.
// https://github.com/coopernurse/node-pool#documentation
'name', 'create', 'destroy', 'reapIntervalMillis', 'returnToHead',
'priorityRange', 'validate', 'validateAsync', 'log'

How to connect to PostgreSQL with epgsql (Erlang)?

I want to run a simple PostgreSQL query with Erlang and epgsql similar to Erlang and PostgreSQL. I am getting
** exception error: no match of right hand side value
{error,
{authentication,
[{severity,'Ð\222Ð\220Ð\226Ð\235Ð\236'},
{code,"28000"},
{message,[208,191,208,190,208,187,209,140,208,183,208,190,208,178,208,176,209,130,208,181|...]},
{file,"auth.c"},
{line,302},
{routine,"auth_failed"}]}}
on
{ok, C} = pgsql:connect("localhost",
"postgres",
"password",
[{database, "postgres"}]).
My PostgreSQL instance works fine and I can add a table to my database or run simple queries. But I need to do it with epgsql. And furthermore, I can't read error message, this is what I can see:
[208,191,208,190,208,187,209,140,208,183,208,190,208,178,208,176,209,130,208,181|...]
I installed egpsql, did a direct test, and confirmed that the second parameter for connect is the username and the third is the password:
{ok, C} = pgsql:connect("localhost", "username", "password", [{database, "db_name"}]).
{ok, Columns, Rows} = pgsql:squery(C, "select * from myschema.mytable").
I have seen similar error 28000 INVALID AUTHORIZATION SPECIFICATION, while using epgsql:connect function.
I have followed the folks suggestion, changing the pg_hba.conf local method type to trust and ident. But no luck!. Tries with, by creating a new user and grant permission on the psql side as well. But no luck.
local all all password #trust
Finally, after the following below update in the pg_hba.conf file(restart of the postgresql service), it is working for me on centos 7.
host all all 127.0.0.1/32 password #ident