526 |
525 |
527 |
526 |
528 ### postgres test database handling ############################################ |
527 ### postgres test database handling ############################################ |
529 |
528 |
530 def startpgcluster(pyfile): |
529 def startpgcluster(pyfile): |
531 """Start a postgresql cluster next to pyfile and using a random port number""" |
530 """Start a postgresql cluster next to pyfile""" |
532 datadir = join(os.path.dirname(pyfile), 'data', |
531 datadir = join(os.path.dirname(pyfile), 'data', |
533 'pgdb-%s' % os.path.splitext(os.path.basename(pyfile))[0]) |
532 'pgdb-%s' % os.path.splitext(os.path.basename(pyfile))[0]) |
534 if not exists(datadir): |
533 if not exists(datadir): |
535 try: |
534 try: |
536 subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C']) |
535 subprocess.check_call(['initdb', '-D', datadir, '-E', 'utf-8', '--locale=C']) |
540 raise OSError('"initdb" could not be found. ' |
539 raise OSError('"initdb" could not be found. ' |
541 'You should add the postgresql bin folder to your PATH ' |
540 'You should add the postgresql bin folder to your PATH ' |
542 '(/usr/lib/postgresql/9.1/bin for example).') |
541 '(/usr/lib/postgresql/9.1/bin for example).') |
543 raise |
542 raise |
544 datadir = os.path.abspath(datadir) |
543 datadir = os.path.abspath(datadir) |
545 pgport = random.randrange(5432, 2**16) |
544 pgport = '5432' |
546 env = os.environ.copy() |
545 env = os.environ.copy() |
547 DEFAULT_PSQL_SOURCES['system']['db-host'] = datadir |
546 sockdir = tempfile.mkdtemp(prefix='cwpg') |
548 DEFAULT_PSQL_SOURCES['system']['db-port'] = str(pgport) |
547 DEFAULT_PSQL_SOURCES['system']['db-host'] = sockdir |
549 options = '-h "" -k %s -p %s' % (datadir, pgport) |
548 DEFAULT_PSQL_SOURCES['system']['db-port'] = pgport |
|
549 options = '-h "" -k %s -p %s' % (sockdir, pgport) |
550 options += ' -c fsync=off -c full_page_writes=off' |
550 options += ' -c fsync=off -c full_page_writes=off' |
551 options += ' -c synchronous_commit=off' |
551 options += ' -c synchronous_commit=off' |
552 try: |
552 try: |
553 subprocess.check_call(['pg_ctl', 'start', '-w', '-D', datadir, |
553 subprocess.check_call(['pg_ctl', 'start', '-w', '-D', datadir, |
554 '-o', options], |
554 '-o', options], |