Question

I have a bash script as such:

GITUSER="mygituser"
DBUSER="mysitedbuser"
DB="mysitedb"
SITE="mysite.com"
REPO="/var/git/myproject.git" # on the server

dropdb -U $DBUSER $DB &&
echo "remote db dump (gzip)" &&
F=`ssh $GITUSER@$SITE $REPO/dumpdb-gzip.sh` &&
echo "copying remote dump to localhost" &&
scp $GITUSER@$SITE:"$F" . &&
echo "deleting remote file" &&
ssh $GITUSER@$SITE rm "$F" &&
echo "loading dump in local db" &&
createdb -U $DBUSER -E UTF8 -O $DBUSER $DB &&
psql -U postgres -c "ALTER SCHEMA public OWNER TO $DBUSER" $DB &&
F=`echo "$F" | sed 's/^\/tmp\///'` &&
zcat "$F" | psql -q -f - -U $DBUSER $DB >/dev/null &&
rm "$F"

But running in on Mac OS X (Lion) gives me this error:

$ ./fetch_server_db.sh
remote db dump (gzip)
copying remote dump to localhost
pg_dump_2011-10-25_09-20-50.db.gz                     100% 1017KB 254.2KB/s   00:04    
deleting remote file
loading dump in local db
ALTER SCHEMA
./fetch_server_db.sh: line 24: 25878 Broken pipe: 13         zcat "$F"
     25879 Segmentation fault: 11  | psql -q -f - -U $DBUSER $DB > /dev/null

I do not have such an error on Snow Leopard and this script continues to work perfectly fine on my arch linux machine. This script is failing with segmentation fault only after I upgraded to Lion.

Any idea what could be the problem? If no immediate answer is obvious, pointing me in the right direction to debug this script or to locate the source of the problem on Mac OS X Lion will do just fine! :-)

UPDATE

I have further isolated this problem to possibly blame it on postgresql 9.0.5. Specifically, when the line:

zcat "$F" | psql -q -f - -U $DBUSER $DB >/dev/null

is being executed (I ran the commands manually one by one in terminal), I get a "Segmentation fault: 11" error from postgresql, like this:

zcat "$F" | psql -q -f - -U mysitedbuser mysitedb >/dev/null
psql:-:32: ERROR:  relation "acl_dummy" already exists
psql:-:46: ERROR:  relation "acl_dummy_id_seq" already exists
Segmentation fault: 11

And this is the psql version I am using on my Lion:

$ psql --version
psql (PostgreSQL) 9.0.5
contains support for command-line editing

$ which psql
/opt/local/lib/postgresql90/bin/psql

$ psql -U postgres
psql (9.0.5)
Type "help" for help.

postgres=# 

Any suggestions what else I can do?

Was it helpful?

Solution

The problem occurs for Xcode 4.2 compiled postgresql packages (screws up both postgresql90 and postgresql91). (see https://trac.macports.org/ticket/30090)

The solution is to write your own Portfile in ~/ports/databases/postgresql90/Portfile by appending somewhere to line 9:

revision:      1

and appending somewhere to line 40:

if {${configure.compiler} == "clang"} { 
configure.compiler llvm-gcc-4.2 
}

Then, copy over the entire "files" subdirectory from /opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/databases/postgresql90/files

Make sure that in /opt/local/etc/macports/sources.conf, add in

file:///Users/whateveryourusernameis/ports

before the url pointing to

rsync://rsync.macports.org/release/tarballs/ports.tar [default]

Then do a portindex in ~/ports or do a sudo port -v selfupdate.

And finally uninstall the previous clang compiled postgresql90 package, clean it:

sudo port -v uninstall postgresql90 postgresql90-server
sudo port clean postgresql90 postgresql90-server

and then reinstall with:

sudo port -v install postgresql90 postgresql90-server

During this reinstallation step, you should notice in the stdout that your postgresql90 packages are now being compiled by llvm-gcc-4.2.

As a general note for compilation of packages via MacPorts, we can choose which compiler to use for a specific package (port) by using the recommendations here - https://trac.macports.org/wiki/PortfileRecipes#compiler

OTHER TIPS

Actually, postgres90@9.0.6 already include this amendment.

You can upgrade just by executing:

sudo port -v uninstall postgresql90
sudo port -v install postgresql90

The same happens with postgresql91

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top