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?

Josh Kraushaar
  • 369
  • 5
  • 17
  • http://www.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` – Dmitry S Sep 09 '15 at 22:22
  • I'm trying to run the file in my terminal through psql. – Josh Kraushaar Sep 09 '15 at 22:54
  • Please check [this answer](http://stackoverflow.com/a/12085561/3961156) in the document I have included above you can find all the options – Dmitry S Sep 09 '15 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? – Josh Kraushaar Sep 09 '15 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. – Dmitry S Sep 09 '15 at 23:19
  • Going further - try to be more specific with your questions, show that you have spent some time investigating the problem (include links you have tried to use, code snippets, etc) with specific question you may get a good answer - otherwise all your questions may be downvoted. – Dmitry S Sep 09 '15 at 23:23

1 Answers1

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
Chad Miller
  • 1,435
  • 8
  • 11
  • Thank you so much, this gave me most of the information I needed to figure it out. Much obliged, sorry for the dumb question. – Josh Kraushaar Sep 10 '15 at 00:57