Stateless services are simple and scalable, but most complex services eventually end up needing persistent state. Fortunately, you can store state in a PostgreSQL database on Render.
We have some examples backed by PostgreSQL to get you started:
You can create a PostgreSQL database on Render in under a minute. Like web services, you can give your database a memorable name (which you can change at any time).
However, the database name and user name cannot be changed after creation. As noted below, we randomly generate them if you omit them.
How you connect to your database depends on your code: some frameworks expect a single connection string or URL in an environment variable, while others need multiple connection parameters in a configuration file. See Getting Started for examples.
At a minimum, your app will need to know your database’s hostname, port, username, password, and database name (e.g.
mydb in the official tutorial).
Render uses the default PostgreSQL port of
5432to connect. Usually, the port can be left unspecified.
The hostname will differ depending on where you’re connecting from. For services deployed on Render, you should always use the internal connection parameters shown below. This minimizes network latency and maximizes app performance.
Using internal connection values is the recommended way for your apps to connect to your Render database. The hostname, username, database, and password are displayed on the database page:
An internal connection string that looks like
postgres://USER:PASSWORD@HOST:PORT/DATABASE is also available if needed. Many database frameworks allow (or require) a connection string instead of individual connection parameters.
You might want to run ad-hoc queries or migrations against your database from machines outside Render. In these cases you can connect to your database using the external connection string on the database page.
Most database clients understand the external connection string, which (like the internal connection string) looks like
postgres://USER:NAME@HOST:PORT/DATABASE. We also provide the PSQL command to connect to your database which can be copied and run in the terminal as is.
Connecting from outside of Render is only meant for one-off situations. You should always perform high-volume or low-latency operations from inside your Render app using internal connection values.
No database is completely insulated from data loss. This is why we take complete database backups every day and retain all backups for 7 days.
You can’t download backup snapshots or restore from them from the dashboard just yet, but we’re more than happy to help you with disaster recovery. Just contact us in chat or shoot us an email at email@example.com.
The major version for your database is fixed when it is created. We don’t do major database version upgrades without your permission, because it can be unsafe to do so.
All new databases are created with the latest major version of PostgreSQL. Currently, that’s version 11.
We will periodically upgrade the minor version of your databases to apply the latest security fixes. Minor version upgrades incur little to no downtime and are done during low-traffic time windows.
Currently, when you delete your database, we do not retain backups or snapshots of your data.