mirror of
https://github.com/jbranchaud/til
synced 2026-01-07 00:58:02 +00:00
Add Run SQL Against Remote Postgres Database as a Heroku TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1391 TILs and counting..._
|
_1392 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -387,6 +387,7 @@ _1391 TILs and counting..._
|
|||||||
|
|
||||||
- [Deploy A Review App To A Different Stack](heroku/deploy-a-review-app-to-a-different-stack.md)
|
- [Deploy A Review App To A Different Stack](heroku/deploy-a-review-app-to-a-different-stack.md)
|
||||||
- [Diagnose Problems In A Heroku Postgres Database](heroku/diagnose-problems-in-a-heroku-postgres-database.md)
|
- [Diagnose Problems In A Heroku Postgres Database](heroku/diagnose-problems-in-a-heroku-postgres-database.md)
|
||||||
|
- [Run SQL Against Remote Postgres Database](heroku/run-sql-against-remote-postgres-database.md)
|
||||||
- [Set And Show Heroku Env Variables](heroku/set-and-show-heroku-env-variables.md)
|
- [Set And Show Heroku Env Variables](heroku/set-and-show-heroku-env-variables.md)
|
||||||
- [SSH Into Heroku Server Hosting App](heroku/ssh-into-heroku-server-hosting-app.md)
|
- [SSH Into Heroku Server Hosting App](heroku/ssh-into-heroku-server-hosting-app.md)
|
||||||
|
|
||||||
|
|||||||
27
heroku/run-sql-against-remote-postgres-database.md
Normal file
27
heroku/run-sql-against-remote-postgres-database.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Run SQL Against Remote Postgres Database
|
||||||
|
|
||||||
|
You can access a remote Heroku PostgreSQL database through a `psql` session
|
||||||
|
using the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
heroku pg:psql --app my-app
|
||||||
|
```
|
||||||
|
|
||||||
|
That opens an interactive psql session.
|
||||||
|
|
||||||
|
If instead you'd like to run a single SQL script against that remote database,
|
||||||
|
you can redirect that script to the connection.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
heroku pg:psql --app my-app < query.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
The results of running that SQL will be written to stdout.
|
||||||
|
|
||||||
|
You can take this a step further by redirecting the output into another file so
|
||||||
|
that you can review and search the results at your convenience, rather than
|
||||||
|
only having them appear in your terminal.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
heroku pg:psql --app my-app < query.sql > results.out
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user