Create and manage Replit's built-in PostgreSQL databases, check status, execute SQL queries with safety checks, and run read-only queries against the production database. Use when the user wants to check prod data, debug database issues in production, or asks to "check the prod db", "query production", "look at live data", or "see what's in the database on the deployed app".
Manage PostgreSQL databases and execute SQL queries safely in your development and production environments.
Use this skill when:
databricks-m2m connector (not the plain databricks connector).Check if the PostgreSQL database is provisioned and accessible.
Parameters: None
Returns: Dict with provisioned (bool) and message (str)
Example:
const status = await checkDatabase();
if (status.provisioned) {
console.log("Database is ready!");
} else {
console.log(status.message);
// Consider calling createDatabase()
}
Create or verify a PostgreSQL database exists for the project.
Parameters: None
Returns: Dict with:
success (bool): Whether operation succeededmessage (str): Status messagealreadyExisted (bool): True if database already existedsecretKeys (list): Environment variables set (DATABASE_URL, PGHOST, etc.)Example:
const result = await createDatabase();
if (result.success) {
console.log(`Database ready! Environment variables: ${result.secretKeys}`);
// Now you can use DATABASE_URL in your application
}
Execute a SQL query with safety checks.
Parameters:
sqlQuery (str, required): The SQL query to executetarget (str, default "replit_database"): Target database: "replit_database", "bigquery", "databricks", or "snowflake"environment (str, default "development"): "development" runs against the development database (all SQL operations supported). "production" runs READ-ONLY queries against a replica of the production database (only SELECT queries allowed). Production is only supported for the "replit_database" target. "production" database, depending on when the user last deployed, may have outdated schemas.sampleSize (int, optional): Sample size for warehouse queries (only for bigquery/databricks/snowflake)Returns: Dict with:
success (bool): Whether query succeededoutput (str): Query output/resultsexitCode (int): Exit code (0 = success)exitReason (str | None): Reason for exit if failedExample:
// Simple SELECT query
const result = await executeSql({ sqlQuery: "SELECT * FROM users LIMIT 5" });
if (result.success) {
console.log(result.output);
}
// CREATE TABLE
const result2 = await executeSql({
sqlQuery: `
CREATE TABLE IF NOT EXISTS products (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
price DECIMAL(10, 2)
)
`
});
// INSERT data
const result3 = await executeSql({
sqlQuery: `
INSERT INTO products (name, price)
VALUES ('Widget', 19.99)
`
});
// Read-only production query
const result4 = await executeSql({
sqlQuery: "SELECT * FROM users WHERE active = true",
environment: "production"
});
// Data warehouse query with sampling
const result5 = await executeSql({
sqlQuery: "SELECT * FROM sales_data WHERE year = 2024",
target: "bigquery",
sampleSize: 100
});
pg package should be installed already.checkDatabase() before createDatabase() to avoid unnecessary operationsAfter creating a database, these environment variables are available:
DATABASE_URL: Full connection stringPGHOST: Database hostPGPORT: Database port (5432)PGUSER: Database usernamePGPASSWORD: Database passwordPGDATABASE: Database name// 1. Check if database exists
const status = await checkDatabase();
if (!status.provisioned) {
// 2. Create database
const createResult = await createDatabase();
if (!createResult.success) {
console.log(`Failed: ${createResult.message}`);
}
}
// 3. Create schema
await executeSql({
sqlQuery: `
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
)
`
});
// 4. Insert data
await executeSql({
sqlQuery: `
INSERT INTO users (email)
VALUES ('[email protected]')
`
});
// 5. Query data
const result = await executeSql({ sqlQuery: "SELECT * FROM users" });
console.log(result.output);
As stated in the diagnostic skills, the development database support rollbacks. Open that skill for more information.