Select a role when connecting to a PostgreSQL database with JDBC - postgresql

How to select a role when connecting to a PostgreSQL database with JDBC?

Use the user connection property, as described in the documentation.

Related

Postgres add user impossible

I get from customer Postgres 8.4, a very strange edition
I login with Postgres user under trust settings.
But in pgAdmin i got a lot of relations errors
I thought normally tables should goes to DB Catalogs Tables, but here DB Catalogs Tables not exists or i cant see them, all tables i see in db Schemas, and database is working as i can access it through ODBC and Postgres connector, but then i see all 2809 tables i a row without separation. It like multi tenat services, but misconfigured or not suit with pgAdmin.
From pgAdmin i cant create any user and roles, from ssh psql created user cant connect through odbc or Postgres connector, and do not appears in pgAdmin Login/Group Roles tab.
So why i cant access in pgAdmin4 Login/Group Roles tab?
Why cant create user from pgAdmin4?
Why cant access pg_catalogs from pgAdmin4?
Why user created from ssh psql cant access database from ODBC or Postgres connector? (got always table is empty)
If this is multi tenant services why it not work like expected from pgAdmin?
PgAdmin 4 version 5.6
PgAdmin4 says it supports 9.5 and newer. 8.4 is not newer than 9.5.

Cloud SQL (GCP) postgres - how to show database number of connections configured

I would like to know the number of connections configured for a postgres database (not the max_connections setting for the instance). By default it is set to -1 (unlimited) but someone has changed that configuration for a particular database. How can I determine what the current setting is for a specific database on a GCP Cloud SQL Postgres instance?
This command is used to change the connection limit for a postgres db:
alter database yourDBName CONNECTION LIMIT nbr;
What is "nbr" for a particular database?
This query will do it:
select
datname as DbName,
datconnlimit as DbConnectionLimit
from
pg_database
order by
datname asc;

Connect to Hive database tables using postgresql-fdw from postgresql server

Cant connect from postgresql server to hive databases on remote server.
Tried using the following queries but doenst work. Connection established but no response back from hive server.
--create extension postgres_fdw;
DROP USER MAPPING IF EXISTS FOR CURRENT_USER SERVER data_db;
drop server data_db;
create server data_db
foreign data wrapper postgres_fdw
options (host 'net.com' , port 'hiveport' , SSLMODE 'allow', dbname 'datah');
create user mapping for current_user
server data_db
options(user 'user', password 'password');
drop schema app;
create schema app;
import foreign schema public
from server data_db
into app;
The result was unknown expecting authentication request from the server (SQL state 08001).
I would like to be able to establish a connection to the hive database clusters using the fdw from postgresql to import selective data.
Thank you very much in advance and best regards!
postgres_fdw is for connecting to other PostgreSQL instances. Hive doesn't use the same wire protocol as PostgreSQL does, so surely postgres_fdw would not be expected to connect to it successfully. Perhaps you can try https://github.com/youngwookim/hive-fdw-for-postgresql or https://sourceforge.net/projects/hadoopfdw/.

Postgres: Using dblink to make remote connection

We got a Postgres database credentials (with SSL on) from our contractor, which allow us to connect to the DB using pdAdmin 3. The DB is read-only (can't do pg_dump) to us and basically the contractor will not grant us more privileges.
We need to fetch some data from this remote DB to our local DB. So I wanted to use dblink to perform this task.
I run this on psql:
insert into shifts select * from dblink('hostaddr=remote_addr port=9000 dbname=production user=user password=passwd', 'select user_id, location_id from shifts') as t1(user_id integer, location_id integer);
Then I got:
ERROR: password is required DETAIL: Non-superuser cannot connect if
the server does not request a password. HINT: Target server's
authentication method must be changed.
Since I am new to Postgres and dblink, I have no idea why it is complaining there is no password. And I wonder, to do a dblink connection, does the remote database needs to grant any more privileges?
If the pdAdmin 3 is able to connect to the remote DB with the credentials, what should I do to make dblink work?
Thanks!
Yes only superuser can provide you to the facility to connect through DBLINK
just run this command below whether you are able to connect to database
SELECT dblink_connect('myconn', 'dbname=postgres');
SELECT dblink_connect('myconn', 'hostaddr=remote_addr port=9000 dbname=production user=user password=passwd');
just give the name of database u want to connect after dbname
You can connect
dblink_connect_u
dblink_connect_u() is identical to dblink_connect(), except that it
will allow non-superusers to connect using any authentication method.
Link on postgres site is
dblink
For Superuser ask them to create extension
CREATE EXTENSION dblink;
for your database or schema .

How many dblink connections can be opened in postgres

As autonomus transactions are not avaliable in postgres we are using dblink as a workaroud but there is a scenerio which is as
linked from Does Postgres support nested or autonomous transactions?
select * from dblink_connect('TEST1','host=localhost port=5432 dbname=tyguy user=postgres password=postgres') as t1(text);
Then when we use the method
SELECT dblink_get_connections();
then only one connection is visible that is absolutely correct named as 'TEST1'
but when i open a new pg admin window or a new session then the same is not avaliable as
SELECT dblink_get_connections();
returns empty. No connection of name 'TEST1'
I am confused is DBlink is at database level ? or session level .
if it is at session level then how many dblink named connections can be opened in a database.