Posts

Showing posts from July, 2025

Postgres: To check index and their columns on a table

Image
    SELECT         t.relname AS table_name,         i.relname AS index_name,         string_agg(a.attname, ', ') AS indexed_columns     FROM         pg_class t     JOIN         pg_index ix ON t.oid = ix.indrelid     JOIN         pg_class i ON i.oid = ix.indexrelid     JOIN         pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)     WHERE         t.relkind = 'r' -- 'r' for regular tables         AND t.relname = 'coupons' -- Optional: filter for a specific table     GROUP BY         t.relname, i.relname     ORDER BY         t.relname, i.relname;

MySQL: Shutdown a schema / database

  In MySQL, you cannot "shut down" a specific schema (database) as you would a server or service. However, you can restrict access to a schema or make it effectively inaccessible by taking certain actions. Here are some approaches: 1. Revoke User Privileges You can revoke all privileges for specific users on the schema to prevent access. Copy the code REVOKE ALL PRIVILEGES ON schema_name. * FROM 'username' @ 'host' ; Replace  schema_name  with the name of your schema, and  username  and  host  with the appropriate user and host. 2. Rename the Schema Renaming the schema can make it temporarily inaccessible to applications or users relying on the original name. Copy the code RENAME DATABASE old_schema_name TO new_schema_name; Note:  This is supported in some MySQL versions but not all. Always back up your data before attempting this. 3. Lock Tables in the Schema You can lock all tables in the schema to prevent modifications or q...

Postgres: To View what is running on the database

 SELECT * FROM pg_stat_activity where state <> 'idle';

Unix: When AD authorization is not working

 [root@db2tst601 ~]# systemctl status sssd ● sssd.service - System Security Services Daemon    Loaded: loaded (/usr/lib/systemd/system/sssd.service; enabled; vendor preset: enabled)    Active: failed (R esult: exit-code) since Tue 2025-07-15 17:30:04 CDT; 2h 22min ago   Process: 49817 ExecStart=/usr/sbin/sssd -i ${DEBUG_LOGGER} (code=exited, status=1/FAILURE)  Main PID: 49817 (code=exited, status=1/FAILURE) Jul 15 17:28:26 db2tst601 sssd_nss[1663851]: Starting up Jul 15 17:28:27 db2tst601 sssd[49817]: Child [49890] ('TMW.COM':'%BE_TMW.COM') was terminated by own WATCHDOG. Consult corresponding logs to figure out the reason. Jul 15 17:28:27 db2tst601 sssd_be[1664041]: Starting up Jul 15 17:28:29 db2tst601 sssd_nss[1664043]: Starting up Jul 15 17:28:33 db2tst601 sssd[49817]: Exiting the SSSD. Could not restart critical service [nss]. Jul 15 17:29:42 db2tst601 sssd_be[1664041]: Shutting down (status = 0) Jul 15 17:29:43 db2tst601 sssd_pam[857047]: Shuttin...

Unix: To check if all the ports are opened

 [root@db2tst601 ~]# iptables -L

Unix: To uncompress a TAR

 tar -xvzf cb.tar.gz

Postgres: To grant access to database objects

1. Grant Access to All Tables in a Schema To grant access to all tables in a specific schema, you can use the following command: Copy the code GRANT SELECT , INSERT , UPDATE , DELETE ON ALL TABLES IN SCHEMA   To ensure the user gets access to future tables created in the schema, use: Copy the code ALTER DEFAULT PRIVILEGES IN SCHEMA schema_name GRANT SELECT , INSERT , UPDATE , DELETE ON TABLES TO user_name; 2. Grant Access to Specific Tables If you want to grant access to specific tables, use: Copy the code GRANT SELECT , INSERT , UPDATE , DELETE ON table_name TO user_name; Replace  table_name  with the name of the table. 3. Grant Read-Only Access For read-only access to all tables in a schema: Copy the code GRANT SELECT ON ALL TABLES IN SCHEMA schema_name TO user_name; And for future tables: Copy the code ALTER DEFAULT PRIVILEGES IN SCHEMA schema_name GRANT SELECT ON TABLES TO user_name; 4. Using Predefined Roles (PostgreSQ...