16

I am developing a simple PHP application running on Heroku. I have created a CSV file and am using it as a simple database.

Now I want to create a database on Heroku, so I added a Postgres instance and its name is heroku-postgres-9f90a33a::ivory.

I want to know how I can create and manage my database instance to perform actions like creating a table.

0

2 Answers 2

38
  1. First you login to your heroku account
  2. Then you go to databases section 3 There you create a database by clicking on Create Database
  3. Then your heroku database is created and you get to see its details such as

host = ...

database = ...

User = ...

Port = ...

Password = ...

Now Connect to the database using PostgreSQL’s interactive terminal client.

If you don't have it already installed then you’ll have to turn to your platform’s package management suite (e.g. on Ubuntu run sudo apt-get install postgresql-client) or go to postgresql.org, where you’ll find available for download pre-built binary packages suitable for FreeBSD, Linux, Mac, Solaris and Windows, as well as other installation options.

To connect, call psql with the -h option to specify the server’s hostname, -U to specify     the username, and then the database name:

root@yogesh-System-model:~# psql -h [**Host Name**] -U [**User Name**] [**database Name**]
    Password for user hdwvhbehqlishy: ********
    psql (8.4.9, server 9.0.5)
    WARNING: psql version 8.4, server version 9.0.
     Some psql features might not work.
    SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
    Type "help" for help.


df7r55a12o64m4==> CREATE TABLE [Table_name](your_id SERIAL, Name text, Address text);

That will create a table....

I know owner of this question has already solved the problem but still posting this answer for future references....

If any problems can refer this tutorial

This is one way.....another way would be using Jack DB in which you will be able to fire any queries and see the data in your DB located at Heroku.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you this is useful as Heroku's tutorial on php-getting-started glosses over this bit and thus renders the whole tutorial pointless.
Agreed, the Heroku tutorial seems to be nothing more than a challenge issued to the reader to actually get started. This was very helpful.
Just wanted to let other readers know that it looks like Heroku requires building an app now as part of an upgrade, before getting to the DB. Please let me know if I'm missing something or if there's a workaround to only create a database without an app
1

With current Heroku (7.54.1), if the database is your app's primary (which it is by default), you can log in to the psql cli with:

heroku pg:psql --app <name-of-your-app>

Then continue as in the accepted answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.