About psql
To use psql
to connect to your database, you need the connection details for your PostgreSQL server. For more information about how to retrieve your connection details, see the about connecting section.
There are two different ways you can use psql
to connect to your database.
Alternatively, you can use a service URL to provide the details, like this:
If you configured your Timescale Cloud service to connect using SSL mode, use:
Common psql commands
When you start using psql
, these are the commands you are likely to use most frequently:
- For a more comprehensive list of
psql
commands, see the Timescale psql cheat sheet.
When you run queries in psql
, the results are shown in the console by default. If you are running queries that have a lot of results, you might like to save the results into a comma-separated .csv
file instead. You can do this using the COPY
command. For example:
Edit queries in a text editor
Sometimes, queries can get very long, and you might make a mistake when you try typing it the first time around. If you have made a mistake in a long query, instead of retyping it, you can use a built-in text editor, which is based on Vim
. Launch the query editor with the \e
command. Your previous query is loaded into the editor. When you have made your changes, press Esc
, then type :
+w
+q
to save the changes, and return to the command prompt. Access the edited query by pressing ↑
, and press Enter
to run it.