I am running running Mac OS X (10.7.5), PostgreSQL (9.2) and PostGIS (2.0.2) (installed via Postgres.app).

The PostGIS extension seems to work perfectly with vector and raster layers. Once I enable PostGIS for the specific database I am able to create vector and rasters from the SQL Editor of phpAdmin3 (like with ST_MakeEmptyRaster).

The problems begin when I try to load a raster with raster2pgsql. I have no great experience with Postgres (or DBMS in general) so what I did might appear stupid...

I tried to launch it via psql following this steps:

1) Open psql terminal;

2) typed \c mydatabase;

3) Got as prompt mydatabase=# (that I guess means I am logged with owner rights...;

4) Now I tried raster2pgsql -Gbut of course is no SQL so I got ERROR: syntax error at or near "raster2pgsql" LINE 1: raster2pgsql -G;

Then I went back to my Mac OS X terminal shell and into the the folder where my raster2pgsql file is located (/usr/local/pgsql/bin) and typed raster2pgsql -s 4236 -I -C -M *.tif -F -t 100x100 /my/path/to/the/file/myfile.tif myrastertable | psql -U myuser -d mydb -h localhost -p 5432 but I got -bash: raster2pgsql: command not found.

What I am doing wrong?


4 Answers 4


In Windows, the raster2pgsql file is in

C:\Program Files (x86)\PostgreSQL\9.1\bin>raster2pgsql 

In Linux, it's in

/usr/bin (ubuntu)  

In OSX, I have no idea, but have you tried to search it? And yes, that fifth way was the right way.

  • Thank you very much. My problem in Ubuntu was solved using your suggestion.
    – Muser
    Jun 30, 2020 at 9:50

Postgresapp's tools are in a different location - /Applications/Postgres.app/Contents/Versions/9.3/bin. To use a given tool, prepend the full path:

/Applications/Postgres.app/Contents/Versions/9.3/bin/raster2pgsql -s 4236 -I -C -M *.tif -F -t 100x100 /my/path/to/the/file/myfile.tif myrastertable | psql -U myuser -d mydb -h localhost -p 5432

Alternatively, add the directory to your PATH or use alias:

alias raster2pgsql="/Applications/Postgres.app/Contents/Versions/9.3/bin/raster2pgsql"

For permanency, add that line to your .bashrc file.

  • the paths mentioned here are correct but ancient. Later versions of PostgresApp do contain a symlink called latest to the latest included PostgreSQL binaries. To add these to your $PATH the recommended way is: sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp make sure to open a new terminal window afterwards!
    – tbussmann
    Feb 15, 2022 at 18:23

Since Mac OS X is a UNIX based system you should check the file permissions first.

> ls -l raster2pgsql 

-rwxr-xr-x 1 root root 200096 May 23 15:03 raster2pgsql

If it looks like this than you could try to write it like

> ./raster2pgsql

If this works, than your installation directory


is not in the PATH check your PATH variable


If it is not there check out how to put it in your PATH.
The syntax depend very much on the shell you use.
It looks like 'bash' in your case, so use

> export PATH=$PATH:/usr/local/pgsql/bin

That should solve the problem about not finding the executable.
This would be the exact description of your problem.

To make the export permanent, add that to your ~/.bashrc file. Takes effect after re-logging in, or after sourcing the file with something like source ~/.bashrc.
Or, to make the export permanent after reboot, for the entire system, add that to the /etc/profile.d/pgsql.sh file (this may verify by system). The file name itself if arbitrary for a setup like that, and does not need to be executable.


You need to enable the command-line tools to work from your shell

sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql

sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp

sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.