crossdb-query
Execute a SQL file on all PostgreSQL databases on a host. By default, the script will execute the SQL file on all databases on the host. The user can specify a list of databases to include or exclude from the execution. By default, the postgres database is excluded from the execution as well as any template databases.
Features
- Execute SQL files on multiple PostgreSQL databases.
- Include or exclude specific databases.
- List all available databases on the host.
- Debug logging support.
Installation
Using Docker
-
Build the Docker image:
docker build -t crossdb-query .
-
Run the Docker container and bind mount the SQL file:
docker run -it --rm -v $(pwd)/<sql_file>:/app/<sql_file> crossdb-query -u <username> -v <host> -f <sql_file>
Using Python
-
Install using pip:
pip install crossdb-query
-
Run the script:
crossdb_query.py -u <username> -v <host> -f <sql_file>
Usage
usage: crossdb_query.py [-h] [-d] [-f FILE] -u USER -v HOST [-p PORT] [-l] [-i INCLUDE] [-e EXCLUDE]
Execute a SQL file on all PostgreSQL databases on a host. By default, the script will execute the SQL file on all databases on the host. The user can specify a list of databases to include or exclude from the execution.
options:
-h, --help show this help message and exit
-d, --debug Enable debug logging.
-f FILE, --file FILE The SQL file to execute.
-u USER, --user USER The username to connect to the database.
-v HOST, --host HOST The host of the database.
-p PORT, --port PORT The port of the database.
-l, --list List all available databases on the host and exit.
-i INCLUDE, --include INCLUDE
A comma-separated list of databases on which the SQL file will be executed. THe databases must be separated by a comma and no spaces.
-e EXCLUDE, --exclude EXCLUDE
A comma-separated list of databases on which the SQL file will not be executed. The databases must be separated by a comma and no spaces.
Examples
List all databases on the host
$ crossdb_query.py -u <username> -v <host> -l
The script crossdb_query.py wants the password for PostgresDB(host=localhost, port=5432, database=postgres, user=pg_user):
Available databases:
- accounts
- customers
- django_db
- employees
Execute a SQL file on selected databases
$ crossdb_query.py -u <username> -v <host> -f <sql_file> -i accounts,employees
The script crossdb_query.py wants the password for PostgresDB(host=localhost, port=5432, database=postgres, user=pg_user):
Databases selected for execution:
- accounts
- employees
(1/2) Executing on database accounts
Success
(2/2) Executing on database employees
Success
Execute a SQL file on all databases except the specified ones
$ crossdb_query.py -u <username> -v <host> -f <sql_file> -e accounts,employees
The script crossdb_query.py wants the password for PostgresDB(host=localhost, port=5432, database=postgres, user=pg_user):
Databases selected for execution:
- customers
- django_db
(1/2) Executing on database customers
Success
(2/2) Executing on database django_db
Success
Notes
If the user specifies a database that does not exist on the host, the script will ignore the database and continue with the script execution without warning the user.
Metadata
Release files for crossdb-query 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crossdb_query-0.0.2.tar.gz | 44.1 kB | Without provenance | Details for crossdb_query-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crossdb_query-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for crossdb_query-0.0.2-py3-none-any.whl |
Total release size: 74.1 kB
Release files / crossdb_query-0.0.2.tar.gz
| Download URL | crossdb_query-0.0.2.tar.gz |
|---|---|
| Size | 44.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
abed8f718054f2a01f87b3c438b0df8839a73ed9de1f3fef4e7cfd177e8e8746
|
|
BLAKE2b-256 checksum How to use checksums |
76e3a69929e2b6366a7c56c3ab4440139fdbf2bfe57d96b4cb97ab3b11357734
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / crossdb_query-0.0.2-py3-none-any.whl
| Download URL | crossdb_query-0.0.2-py3-none-any.whl |
|---|---|
| Size | 30.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c50f9ef56f77f68b24dbc7f6c2a73a147d995708a7f7388636a16c2051aaa364
|
|
BLAKE2b-256 checksum How to use checksums |
f0367e11c09fb9971ff2380a1914b23f91956bfde71cc699fbd1be5790650362
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Security for crossdb-query 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.