1

I'm currently running Linux Mint 17.2 XFCE, and am currently taking the Udacity Intro to Relational Databases course. A few days ago I installed PostGreSQL as part of the program. A part of the course involved downloading VM and connecting to it via Vagrant to run things on linux, but I'm already running linux so instead I just downloaded Vagrant in order to access the 'forum.sql' file which comes with it and is part of one of the exercises.

However whenever I try to run forum.sql with the command

psql forum.sql

all I get is the

psql: FATAL:  database "forum.sql" does not exist

error. Despite this I'm clearly in the correct directory. When I type 'ls' in the vagrant/forum directory it clearly shows forum.sql.

What am I doing wrong?

6
  • postgresql.org/docs/9.4/static/app-psql.html what are you trying to achieve? have you read psql documentation? you need to use psql -d databaseName -U dbUsername -d host Commented Sep 9, 2015 at 22:22
  • I'm trying to run the file in my terminal through psql. Commented Sep 9, 2015 at 22:54
  • Please check this answer in the document I have included above you can find all the options Commented Sep 9, 2015 at 22:56
  • It seems like from this when I type 'psql' alone in my terminal it should start running, however when I do I just get a similar issue except replace the name of that file with my username. I suspect this might be at the root of my problem. How would I go about correcting this? Commented Sep 9, 2015 at 23:15
  • It is running, no doubt. If you type just psql it gathers your current user (check with whoami). psql is trying to connect with current user and if it does not exist - it will not connect - that's why you need to explicitly set -U option or create role in the database which matches with your terminal user. regarding your error above if you run psql forum.sql for psql it actually psql -d forum.psql - the's why you are getting database does not exit. Commented Sep 9, 2015 at 23:19

1 Answer 1

1

PostgreSQL does not operate on files. When you run "psql", it connects to a service over a kind of network.

What it connects to is the database service, and psql is complaining that the name of the database you told it to use, does not exist.

You may think you want to evaluate the contents of a file, and you can do that, but you have to connect to a database first. If you have in the past run "createdb", then you created a database, and that should be the first parameter on your line after "psql", not some file name. If you don't specify a database name, it will connect to a database with the same name as your linux username, if it has been created too.

If you can connect as you should, and you have verified it, you can then ask psql to read in the file you have using "-f" and then your file name, before the database name.

One of these is possibly correct:

$ psql -f forum.sql databasename
$ psql -f forum.sql
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, this gave me most of the information I needed to figure it out. Much obliged, sorry for the dumb question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.