How to log all DDLs on a gcloud SQL instance? - google-cloud-sql

I would like to log all DDL queries that are run on SQL instance. I tried looking into plugins but they are not allowed.
Edit: It's a MySQL instance.

You may set the Cloud SQL Flag "log_statement" to value "mod" to log all Data definition language (DDL) statements.
The reference link :
https://cloud.google.com/sql/docs/postgres/flags#postgres-l

Related

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.

Run SQL script on multiple schemas with Flyway

I am migrating the DB using Flyway. I have a SQL script file which need to run on multiple schemas hosted on a single database.
In my SQL file if I mention ${db_schema} as the parameter and supply with different schema names, will that work? Is there any other approaches to handle this scenario?
SET search_path TO ${db_schema};
You should be able to use placeholders in flyway to handle more than one schema. Here's an article that outlines how that works.

DB2 Z/OS - Revalidate UDF and Stored Procedure

On DB2 AIX I can use the SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS stored procedure to revalidate all Stored Procedures and Functions defined in my schema.
How can I do the same thing on DB2 z/OS (v.12)?
Thanks
REGENERATE automatically rebinds, at the local server, the package for the SQL control statements for the procedure and rebinds the package for the SQL statements that are included in the procedure body. If a remote bind is also needed, the BIND PACKAGE COPY command must be explicitly done for all of the remote servers.
ALTER PROCEDURE SCHEMA.NAME_SP REGENERATE ACTIVE VERSION;
For the moment I have not found anything that automatically revalidates/regenerates all Stored/UDFs of a Schema.

dBeaver (CE): DB2 LUW Connection with SQL ERROR 42704. Table Schema won't open but able to write SQL queries

After about a year and half, I am finally able to connect to the DB2 database we have through dBeaver. The connection is successful as a LUW (Our db2 is z/os). I was able to get the drivers required after installing IBM Data Studio.
Once I am connected, I go down the schema, get to Tables, and on clicking that, I get the below error.
SQL Error [42704]: SYSCAT.SCHEMATA IS AN UNDEFINED NAME. SQLCODE=-204, SQLSTATE=42704, DRIVER=3.69.56
SYSCAT.SCHEMATA IS AN UNDEFINED NAME. SQLCODE=-204, SQLSTATE=42704, DRIVER=3.69.56
THE DESCRIBE STATEMENT DOES NOT SPECIFY A PREPARED STATEMENT. SQLCODE=-516, SQLSTATE=26501, DRIVER=3.69.56
THE CURSOR SQL_CURLH200C1 IS NOT IN A PREPARED STATE. SQLCODE=-514, SQLSTATE=26501, DRIVER=3.69.56
SQL Error [42704]: SYSCAT.SCHEMATA IS AN UNDEFINED NAME. SQLCODE=-204, SQLSTATE=42704, DRIVER=3.69.56
However, if ignore the error and go to New SQL query and write a simple
Select * from schema.table
it works fine and get the results I want.
Considering the time i have spent to get till here, this is sufficient, but to deploy as a solution in my department, I need to be able to look at a Table List (schema).
Any help would be awesome.
EDIT1: What the issue is here, is that there is no SCHEMA with the name SYSCAT and no table named SCHEMATA.
The z/OS Db2 catalog has different names than the ones used on Db2 on distributed (Linux Unix Windows aka LUW). Here is a list of objects on Db2 z/OS that you can review.
It looks like you are using dBeaver to navigate through a UI the objects on Db2 for z/OS. You will need to ensure you have a db2 jcc driver that is for z/OS Db2. It looks like you may be using one from LUW as the SYSCAT.SCHEMATA is an LUW object, not a z/OS object.
Your other query works because you are specifying a known table name. Other queries should be fine. The issue is the interface in dbeaver is looking at Db2 system objects for LUW and not z/OS. This will continue until you are able to resolve the driver issue.
The IBM Data Server Drivers also require server sided set-up. Please see this information https://www.ibm.com/support/knowledgecenter/SSEPEK_12.0.0/java/src/tpc/imjcc_jccenablespsandtables.html
In DBeaver, when you create a connection choose the "DB2 z/OS driver" option under the Db2 drop down, when connecting to DB2 for z/OS
BTW DBeaver can shell share with Data Studio, so you can (if you wish) use both products in one install. No guarantees that they share happily in all cases, but it appears to work reasonably well.

Setting up environment for SQL queries

I know the basic syntax of queries but otherwise I'm a beginner with SQL.
I have an SQL file (.sql) and I downloaded a couple programs (pgadmin and sql workbench).
I have no idea how to get from where I am now to actually writing queries and finding information. How do I set up so I can actually import my SQL file and start writing queries?
pgAdmin is the default GUI for PostgreSQL.
SQL Workbench is a free, DBMS-independent, cross-platform SQL query tool.
Either way, you need to connect to a database to actually run queries. The DBMS can either run on your local machine or you can connect to a remote server - where you need access privileges of course.