Skip to content

Latest commit

 

History

History
98 lines (85 loc) · 3.17 KB

Babelfish Useful Scripts.md

File metadata and controls

98 lines (85 loc) · 3.17 KB

Babelfish Useful Scripts

❗Always refer to the latest Babelfish and Aurora PostgreSQL documentation for the most accurate and detailed information.

These scripts typically help with configuration, diagnostics, and compatibility checks, making the migration and interoperability between SQL Server and Aurora PostgreSQL smoother. Here are some common and useful types of scripts:


  1. Version and Compatibility Checks Scripts to check the version of Babelfish and ensure compatibility with SQL Server syntax.
    SELECT SERVERPROPERTY('babelfishversion') AS BabelfishVersion, aurora_version() AS AuroraPostgreSQLVersion;

  1. Database Creation and Configuration Scripts to create databases and configure them for use with Babelfish.
    CREATE DATABASE myDatabase;
    EXECUTE sp_babelfish_configure 'myDatabase', 'enabled', 'true';

  1. Escape Hatches Configuration Adjusting Babelfish escape hatches controls how certain SQL Server behaviors are handled.
    EXECUTE sp_babelfish_configure 'escape_hatch_session_setting', 'ignore';
    EXECUTE sp_babelfish_configure 'escape_hatch_storage_engine', 'ignore';

  1. Object Mapping Information Scripts to check the mapping of SQL Server objects to PostgreSQL.
    SELECT * FROM sys.babelfish_namespace_ext WHERE dbname = 'myDatabase';

  1. Monitoring and Diagnostics Queries to monitor the performance and diagnose issues.
    SELECT * FROM pg_stat_activity WHERE datname = 'myDatabase';
    SELECT * FROM babelfishpg_tsql.sys_dm_exec_requests;

  1. Security and User Management Managing users and permissions is especially important due to differences in security models between SQL Server and PostgreSQL.
    CREATE USER myUser WITH PASSWORD 'myPassword';
    GRANT ALL PRIVILEGES ON DATABASE myDatabase TO myUser;

  1. Data Import/Export Scripts to facilitate data migration between SQL Server and Aurora PostgreSQL.
    -- Exporting data from SQL Server
    BCP myDatabase.dbo.myTable OUT datafile.bcp -c -T
    
    -- Importing data into Aurora PostgreSQL
    COPY myTable FROM '/path/to/datafile.bcp';

  1. Routine Maintenance Tasks Regular maintenance tasks like vacuuming, analyzing tables, or checking for index bloat.
    VACUUM FULL VERBOSE ANALYZE myTable;
    SELECT * FROM pg_stat_user_indexes WHERE idx_tup_read > idx_tup_fetch;

  1. Transaction and Lock Management Scripts to view and manage transactions and locks, particularly useful in troubleshooting performance issues.
    SELECT * FROM pg_locks WHERE granted = false;
    SELECT * FROM babelfishpg_tsql.sys_dm_tran_active_transactions;

  1. Check the mapping between Babelfish and PostgreSQL
SELECT 
    pg.dbname AS babelfishDBName,
    be.orig_name AS schemaname,
    pg.nspname AS pgSchemaNameForDMS,
    pg.oid,
    SCHEMA_ID(be.orig_name) AS MapsToPGOID
FROM 
    sys.pg_namespace_ext AS pg 
INNER JOIN 
    sys.babelfish_namespace_ext AS be 
    ON pg.nspname = be.nspname 
WHERE 
    dbname = DB_NAME() 
ORDER BY 
    schemaname;