Re: Execute commands in single-user mode

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Andreas Joseph Krogh <andreas(at)visena(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Execute commands in single-user mode
Date: 2016-01-10 15:12:53
Message-ID: CANu8FiySPbFOjRpmHs1++M9ngAjDCpSWL7Fk2dnK67hjYDYcuA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sorry, I've never used single user mode,
but here is a better example

#!/bin/bash
echo "******CHANGING TABLESPACES******"
gosu postgres postgres --single -O -D $PGDATA $DB_NAME<<- EOSQL
alter table pg_largeobject set tablespace some_tablespace;
EOSQL
pg_ctl stop -d $PGDATA -m fast
echo ""
echo "******TABLESPACES CHANGED******"

fyi, revised from
http://stackoverflow.com/questions/28244869/creating-a-table-in-single-user-mode-in-postgres

On Sun, Jan 10, 2016 at 10:01 AM, Andreas Joseph Krogh <andreas(at)visena(dot)com>
wrote:

> På søndag 10. januar 2016 kl. 15:52:12, skrev Melvin Davidson <
> melvin6925(at)gmail(dot)com>:
>
> Well, you can't combine psql with the postgres startup, but you can issue
> subsequent commands from bash with the -c option:
>
> EG:
>
> postgres --single -O -D $PGDATA $DB_NAME
> # give postgres a few seconds to complete startup
> sleep 30
> psql -U postgres -d your_database -c "alter table pg_largeobject set
> tablespace some_tablespace;"
>
> pg_ctl stop -d $PGDATA -m fast
>
>
> How can that work?
>
> Starting in single-mode gives you a prompt, so there's no way to issue
> another command. Even if it was, PG is not accepting connections, so using
> psql won't work, unless I'm misstaken...
>
>
> BTW, it's always good form to state the exact O/S and version of
> PostgreSQL, regardless of whether you think it may apply.
>
>
> Yea, sorry, it's 9.5.0
>
> --
> *Andreas Joseph Krogh*
> CTO / Partner - Visena AS
> Mobile: +47 909 56 963
> andreas(at)visena(dot)com
> www.visena.com
> <https://www.visena.com>
>
>

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2016-01-10 15:36:23 Re: Code of Conduct: Is it time?
Previous Message Andreas Joseph Krogh 2016-01-10 15:01:35 Re: Execute commands in single-user mode