The problem is that you've launched psql
as the user postgres
and you haven't granted the postgres
user permission to read the SQL file. You'll need to give it permission. The simplest way is to grant world read rights:
chmod a+r create.sql
You can change the default permissions assigned to files by altering your umask
; search for more information. Some programs rather annoyingly ignore the umask
and set restrictive file permissions anyway, so you always need to know how to grant permissions. See man chmod
and man chown
.
BTW, you're using a very convoluted method for launching psql
as the postgres
user. This'll do just fine:
sudo -u postgres psql template1
Note that /create.sql
specifies a file named create.sql
in root of the file system (/
). I doubt this is what you intended.
You probably want to specify it as a relative path (without the leading /
) if it's in your home directory, like:
template1=# \i create.sql
or if it's on the desktop and you've started psql
in your home directory:
template1=# \i Desktop/create.sql