More actions
Add PostgreSQL page |
Add information about connection URIs |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
[https://www.postgresql.org/ PostgreSQL] is a popular and widely-used SQL relational database | [https://www.postgresql.org/ PostgreSQL] is a popular and widely-used SQL relational database used for projects of any size. Since it's used so often, Nest runs an instance of Postgres that you can use without having to spin up a whole new instance that could use a lot of resources. | ||
== How to use Nest Postgres == | == How to use Nest Postgres == | ||
Nest Postgres is just a simple instance of PostgreSQL | Nest Postgres is just a simple instance of PostgreSQL 17 that you can access with your Nest username and password. To launch the Postgres client, you can simply run: | ||
psql | psql | ||
and you'll enter the interactive Postgres shell where you can run SQL like normal. Since Nest Postgres is publicly accessible, you can also connect to it from any other machine, including wherever your apps may run, such as Vercel! | and you'll enter the interactive Postgres shell where you can run SQL like normal. Since Nest Postgres is publicly accessible, you can also connect to it from any other machine, including wherever your apps may run, such as Vercel! | ||
When you're just using the <code>psql</code> client on Nest, you don't need to specify your username and password, but if you're connecting to Postgres over a network, then you will need to authenticate. Your username and password will be the same username and password that you use for Nest! | |||
=== Databases === | |||
By default, a Postgres database is created for you, with your Nest username as the database name. You can connect to your database by running the following in the Postgres client: | |||
\c <username>; | |||
If you'd like to create new databases, no worries! You can create a new database with the [[Nest CLI]], by running | |||
nest db create <name> | |||
The Nest CLI will create a new database for you with your Nest username prefixed to it - for example, if your Nest username was <code>orpheus</code> and you ran <code>nest db create slackbot</code>, the new database would be named <code>orpheus_slackbot</code>. | |||
=== Connecting === | |||
Nest's Postgres is publicly accessible over the network. When connecting over the network, use a connection URI of the format<syntaxhighlight lang="text"> | |||
postgres://username:password@hackclub.app/username_database | |||
</syntaxhighlight>where <code>username</code> is your Nest username, and <code>password</code> is your password. After the <code>/</code> is your database name. | |||
When connecting from within Nest itself (including from a container), use a connection URI of this format:<syntaxhighlight lang="text"> | |||
postgres://username@localhost/username_database?sslmode=disable&host=/var/run/postgresql | |||
</syntaxhighlight>Since you're connecting from within Nest (using your user account), you don't need to provide your password to authenticate! This is also how <code>psql</code> is able to connect to your database without needing your password. | |||
Latest revision as of 01:36, 26 July 2025
PostgreSQL is a popular and widely-used SQL relational database used for projects of any size. Since it's used so often, Nest runs an instance of Postgres that you can use without having to spin up a whole new instance that could use a lot of resources.
How to use Nest Postgres
Nest Postgres is just a simple instance of PostgreSQL 17 that you can access with your Nest username and password. To launch the Postgres client, you can simply run:
psql
and you'll enter the interactive Postgres shell where you can run SQL like normal. Since Nest Postgres is publicly accessible, you can also connect to it from any other machine, including wherever your apps may run, such as Vercel!
When you're just using the psql client on Nest, you don't need to specify your username and password, but if you're connecting to Postgres over a network, then you will need to authenticate. Your username and password will be the same username and password that you use for Nest!
Databases
By default, a Postgres database is created for you, with your Nest username as the database name. You can connect to your database by running the following in the Postgres client:
\c <username>;
If you'd like to create new databases, no worries! You can create a new database with the Nest CLI, by running
nest db create <name>
The Nest CLI will create a new database for you with your Nest username prefixed to it - for example, if your Nest username was orpheus and you ran nest db create slackbot, the new database would be named orpheus_slackbot.
Connecting
Nest's Postgres is publicly accessible over the network. When connecting over the network, use a connection URI of the format
postgres://username:password@hackclub.app/username_databasewhere username is your Nest username, and password is your password. After the / is your database name.
When connecting from within Nest itself (including from a container), use a connection URI of this format:
postgres://username@localhost/username_database?sslmode=disable&host=/var/run/postgresqlSince you're connecting from within Nest (using your user account), you don't need to provide your password to authenticate! This is also how psql is able to connect to your database without needing your password.