How to create multiple databases with Postgres in pgAdmin4 - postgresql

I am trying to run the following query in pgAdmin:
CREATE DATABASE abc;
CREATE DATABASE xyz;
And I get the following error:
ERROR: current transaction is aborted, commands ignored until end of transaction block
SQL state: 25P02
I'm relatively new to postgres.
With SQL Server it's possible to create multiple databases in a single query with the "GO" statement in between if necessary.
I've tried to google this error, and most answers are to simply run each line separately.
That would work, but I'm curious why this doesn't work.
It may also be a setting in pgAdmin.
The "autocommit" is currently on. I've tried it off, and same result.
I'm using postgres 14.5 (in aws)

Related

Exasol not exporting in parallel to PostgreSQL

We have a connection in Exasol (v7.0.18) to PostgreSQL (v14) created like this
create or replace connection POSTGRES_DB to
'jdbc:postgresql://hostname:5432/my_db?useCursorFetch=true&defaultFetchSize=2147483648'
user 'abc'
identified by <>;
I am running an export statement using this connection like this:
EXPORT MY_SCHEMA.TEST_TABLE
INTO JDBC AT POSTGRES_DB
TABLE pg_schema.test_table
truncate;
This works without any error.
The issue is that it runs only one insert statement in the PostgresSQL at a time. I am expecting multiple inserts running at a time in PostgresSQL.
This documentation page says Importing from Exasol databases is always parallelized. For Exasol, loading tables directly is significantly faster than using the STATEMENT option.
How can I make the export statement do parallel insert into PostgreSQL?

PostgreSQL 11.16 cannot execute CREATE TABLE in a read-only transaction

I have a PostgreSQL database running on an Azure machine. When I try to create a table on a database, I get an error "cannot execute CREATE TABLE in a read-only transaction". The SQL query is being executed by a python script using a sqlalchemy engine. But I tried a similar query in PGAdmin installed on my machine and I get the same error. And I noticed that I do not have this issue if I connect to the database from a colleague's machine.
After further research, I found that if I execute SELECT pg_is_in_recovery(); in my PGAdmin, it returns true. And false on my colleague's machine.
Let me know if there is any way to correct this
SELECT pg_is_in_recovery() - returned true = Database has only Read Acces
can you check your permission?
you can check postgresql.conf file and atribute default_transaction_read_only
or try this:
begin;
set transaction read write;
alter database exercises set default_transaction_read_only = off;
commit;
The issue was that our posgtresql machine is a HA machine, and that I was connecting to an IP address rather than the domain.

SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;reorg ;JOIN <joined_table>

when running this query on db2 on DBeaver :
reorg table departments
i got this error (just on external channel):
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;reorg ;JOIN <joined_table>, DRIVER=4.19.49
what does this query mean?
how can I fix the error?
appricicate any help.
Try call sysproc.admin_cmd('reorg table db2inst1.departments')
as you are using DBeaver which is a jdbc application.
If you do not qualify the table name (for example, with db2inst1) then Db2 will assume that the qualifier (schema name) is the same as the userid name you used when connecting to the database.
DBeaver runs SQL statements, but it cannot directly run commands of Db2 - instead, any jdbc app can run Db2-commands indirectly via a stored-procedure that you CALL. The CALL is an SQL statement.
The reorg table is a command, it is not an SQL statement, so it needs to be run via the admin_cmd stored-procedure, or it can be run from the operating system command line (or db2 clp) after connecting.
So if you have db2cmd.exe on MS-Windows, or bash on linux/unix, you can connect to the database, and run commands via the db2 command.

Oracle READ WRITE mode in postgres

I am migrating Oracle database to Postgres Aurora. There is one Oracle PL/SQL block which checks if the database is in read write open mode. Below is the query like:
Select open_mode into v_open_mode from v$database;
if v_open_mode = 'READ WRITE' then
-- perform some steps.
I want to know if we have any equivalent query in Postgres. Or even if I can know the postgres node is WRITE mode.
I am also open to get anything which is native to Aurora which show if the node is reader or writer.
I am not sure what the Oracle thing does, but I assume the closest thing would be to check if Postgres is in recovery mode using pg_is_in_recovery()
So something like:
if not pg_is_in_recovery() then
-- do some steps
end if;
That is from "stock" Postgres, I don't know if Amazon Aurora does anything different or provides other functions.

Postgres alter system command fails using Hibernate fails

I want to make a change to the postgres.conf file at runtime. However, when I execute the sql with "alter system" via hibernate I get an error
Transaction is marked for rollback only or has timed out
I think this has something to do with alter system commands not allowed to execute inside a transaction block as per the documentation
Only superusers can use ALTER SYSTEM. Also, since this command acts directly on the file system and cannot be rolled back, it is not allowed inside a transaction block or function.
Im trying to understand if its possible to execute this type of command with hibernate and what I need to do to be able to do that?