Write and run queries in PG Studio
Use the SQL editor in PG Studio to write, edit, and execute queries.
PG Studio is on by default. If it is off for your organization, PG Studio shows a message to contact Aiven support and you cannot open the editor or run queries. Aiven manages this control. To change it, contact the Aiven support team. See Manage PG Studio and AI features.
Write SQL manually
-
In the SQL editor, enter your query.
UseTabto autocompletePress the
Tabkey to autocomplete SQL keywords, table names, column names, and other database objects from your schema. When the autocomplete list is open, use the arrow keys to move between suggestions and pressEnterorTabto insert the selected suggestion. PressEscto dismiss autocomplete. -
Click Run.
-
View the results in the results panel.
The autocomplete feature helps you write queries faster by suggesting:
- SQL keywords and clauses:
SELECT,FROM,WHERE,JOIN - Table names from your selected schema
- Column names from tables in your query
- Database functions and operators
Run a single query
When the editor contains multiple SQL statements and you don't select any text, Run executes only the statement where your cursor is placed.
- In the SQL editor, place your cursor inside the query you want to run, without selecting any text.
- Click Run.
- View the results in the results panel.
This is useful for:
- Testing individual queries from a larger script
- Iterating on a single query while keeping other statements in context
- Testing each subquery independently before combining a complex query
- Verifying data in a specific table without executing setup or cleanup statements
Run multiple queries
You can write several SQL statements in the editor and run them all at once. To run all statements, select them first. Run executes all statements only when they are all selected; otherwise it runs only the statement where your cursor is placed. PG Studio runs the selected statements sequentially and displays the results in separate tabs.
-
In the SQL editor, write your SQL statements:
SELECT count(*) FROM orders;
SELECT * FROM users LIMIT 10; -
Select all the statements you want to run.
-
Click Run.
-
View the results in the results panel. When more than one statement runs, each result appears in its own tab labeled Query 1, Query 2, and so on:
- A red error indicator on a tab means the statement encountered an error. If a statement fails, execution stops and remaining statements are not run. Results from statements that completed before the error are preserved.
This is useful for:
- Running a sequence of setup, query, and cleanup statements in one go
- Executing a batch of related queries and comparing their results
- Validating multiple statements before saving or sharing a script
Execute queries
When you run a query, whether generated by the AI or written manually:
- PG Studio automatically detects the query type and applies appropriate safeguards.
- The editor executes it unless it is a write operation, in which case PG Studio prompts you to confirm before execution as a safety measure.
- The results panel displays your query results. When running multiple statements, each result appears in its own tab.
Run write queries
You can execute data modification and data definition statements directly against your database.
To run a write query:
- In the SQL editor, enter your write query.
- Click Run.
- PG Studio detects the write operation and shows You are changing live data.
- Choose how to proceed:
- Run on production runs the query directly against the connected database.
- Test on a fork creates a fork so you can test the query without changing live data.
- Optional: Select Don't ask me again to skip this confirmation for future write queries on this service.
View and revert write query history
PG Studio keeps a change log of write queries you run. You can review changes and create a fork from a point in time before a specific write query.
To view the change log:
- In the SQL editor, click Change log. This option appears after you run at least one write query.
- In Change log, review each write query with its timestamp and query preview.
To create a fork from a point before a specific write query:
- Open Change log.
- Select the write query you want to roll back to.
- Click Create fork. PG Studio opens Create fork with a recovery timestamp set to the moment before that query ran.
Query execution limits
PG Studio applies these limits to query execution:
- Statement timeout: 30 seconds
- Lock timeout: 10 seconds
- Connection timeout: 10 seconds
- Maximum result size: 1,000 rows per statement
- Maximum statements per run: 10
- Rate limiting: 10 query executions per 10 seconds per user per service
- AI rate limiting: One AI request every two seconds per user per service
Explore tables in the query editor
Use Tables in the query editor to browse your database tables and start to run SQL queries. The table list uses your selected source database and schema.
To use the Tables view:
- Open PG Studio.
- Select Tables in the query editor.
- Select a source database and schema.
- Select a table from the list.
When you open a table, PG Studio shows up to 100 rows.
From Tables, you can open a table tab and use it as a starting point for querying that table. For column definitions and relationships, use Open schema map.