Обсуждение: postgres with xcode

Поиск
Список
Период
Сортировка

postgres with xcode

От
Sumit Chaturvedi
Дата:
Hello everyone. I'm a third year student from IIT Bombay, India. Since I'm currently learning about databases, I wanted to debug postgresql with xcode. However, I am having a lot of problems. 
OS - 10.13.6 (High Sierra)
Xcode - 9.4.1

To set up my system, I tried to replicate the instructions found at https://wiki.postgresql.org/wiki/Working_with_Eclipse for my case. 

Everything proceeded fine until a point where I had to change the run configuration (scheme in xcode terms). I set the executable as postgre from /src/backend and gave the appropriate arguments. Then, when I pressed run, I got an error as shown in the attachment. 
To solve it, I set up my environment variables in xcode appropriately to make sure that locale information was reaching wherever it was needed. But even now, when I press run I get the same error. 

Hoping someone can share with me how they went about with their setup. 

--
Sumit Chaturvedi
Вложения

Re: postgres with xcode

От
Adrian Klaver
Дата:
On 07/28/2018 04:04 AM, Sumit Chaturvedi wrote:
> Hello everyone. I'm a third year student from IIT Bombay, India. Since 
> I'm currently learning about databases, I wanted to debug postgresql 
> with xcode. However, I am having a lot of problems.
> OS - 10.13.6 (High Sierra)
> Xcode - 9.4.1
> 
> To set up my system, I tried to replicate the instructions found at 
> https://wiki.postgresql.org/wiki/Working_with_Eclipse 
> <https://wiki.postgresql.org/wiki/Working_with_Eclipse> for my case.
> 
> Everything proceeded fine until a point where I had to change the run 
> configuration (scheme in xcode terms). I set the executable as postgre 
> from /src/backend and gave the appropriate arguments. Then, when I 
> pressed run, I got an error as shown in the attachment.

I can tell you where the error comes from:

postmaster.c

/*
* On macOS, libintl replaces setlocale() with a version that calls
* CFLocaleCopyCurrent() when its second argument is "" and every relevant
* environment variable is unset or empty.  CFLocaleCopyCurrent() makes
* the process multithreaded.  The postmaster calls sigprocmask() and
* calls fork() without an immediate exec(), both of which have undefined
* behavior in a multithreaded program.  A multithreaded postmaster is the
* normal case on Windows, which offers neither fork() nor sigprocmask().
*/
if (pthread_is_threaded_np() != 0)
     ereport(FATAL,
                     (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                         errmsg("postmaster became multithreaded during 
startup"),
                         errhint("Set the LC_ALL environment variable to 
a valid locale.")));

> To solve it, I set up my environment variables in xcode appropriately to 
> make sure that locale information was reaching wherever it was needed. 
> But even now, when I press run I get the same error.

I do not see that the LC_ALL environment variable is set, per the HINT 
to the FATAL message.

> 
> Hoping someone can share with me how they went about with their setup.
> 
> -- 
> Sumit Chaturvedi


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: postgres with xcode

От
Adrian Klaver
Дата:
On 07/28/2018 07:15 AM, Sumit Chaturvedi wrote:
Please reply to list also.
Ccing list.

> Hello. Thanks a lot for your response. Yes that was also there.

Note: Bottom posting is the style on this list. Unfortunately the 
screenshot is not coming through on this reply. For those that see this 
the screenshot showed:

LC_ALL en_US.UTF8

Generally it is a better idea to cut and paste from command line output 
or a text file then show a screenshot. For the reason above and also 
because screenshots make it difficult for other users to cut and paste 
into their machines for testing/debugging purposes.

Back to the problem at hand. The error message only shows up in the 
section I quoted before with regards to locale handling on Macs.

Are you having any issues with starting Postgres outside of xcode?

> 
> On Sat, Jul 28, 2018 at 7:41 PM Adrian Klaver <adrian.klaver@aklaver.com 
> <mailto:adrian.klaver@aklaver.com>> wrote:
> 
>     On 07/28/2018 04:04 AM, Sumit Chaturvedi wrote:
>      > Hello everyone. I'm a third year student from IIT Bombay, India.
>     Since
>      > I'm currently learning about databases, I wanted to debug postgresql
>      > with xcode. However, I am having a lot of problems.
>      > OS - 10.13.6 (High Sierra)
>      > Xcode - 9.4.1
>      >
>      > To set up my system, I tried to replicate the instructions found at
>      > https://wiki.postgresql.org/wiki/Working_with_Eclipse
>      > <https://wiki.postgresql.org/wiki/Working_with_Eclipse> for my case.
>      >
>      > Everything proceeded fine until a point where I had to change the
>     run
>      > configuration (scheme in xcode terms). I set the executable as
>     postgre
>      > from /src/backend and gave the appropriate arguments. Then, when I
>      > pressed run, I got an error as shown in the attachment.
> 
>     I can tell you where the error comes from:
> 
>     postmaster.c
> 
>     /*
>     * On macOS, libintl replaces setlocale() with a version that calls
>     * CFLocaleCopyCurrent() when its second argument is "" and every
>     relevant
>     * environment variable is unset or empty.  CFLocaleCopyCurrent() makes
>     * the process multithreaded.  The postmaster calls sigprocmask() and
>     * calls fork() without an immediate exec(), both of which have undefined
>     * behavior in a multithreaded program.  A multithreaded postmaster
>     is the
>     * normal case on Windows, which offers neither fork() nor sigprocmask().
>     */
>     if (pthread_is_threaded_np() != 0)
>           ereport(FATAL,
>                         
>       (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
>                               errmsg("postmaster became multithreaded
>     during
>     startup"),
>                               errhint("Set the LC_ALL environment
>     variable to
>     a valid locale.")));
> 
>      > To solve it, I set up my environment variables in xcode
>     appropriately to
>      > make sure that locale information was reaching wherever it was
>     needed.
>      > But even now, when I press run I get the same error.
> 
>     I do not see that the LC_ALL environment variable is set, per the HINT
>     to the FATAL message.
> 
>      >
>      > Hoping someone can share with me how they went about with their
>     setup.
>      >
>      > --
>      > Sumit Chaturvedi
> 
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 
> -- 
> Sumit Chaturvedi


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: postgres with xcode

От
Sumit Chaturvedi
Дата:
Hello.

Thanks for those pointers. Will keep them in mind in the future. No, there is no problem outside Postgres.

Could it be that postmaster becomes multithreaded for some other reason??

On Sat, Jul 28, 2018 at 9:57 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 07/28/2018 07:15 AM, Sumit Chaturvedi wrote:
Please reply to list also.
Ccing list.

Hello. Thanks a lot for your response. Yes that was also there.

Note: Bottom posting is the style on this list. Unfortunately the screenshot is not coming through on this reply. For those that see this the screenshot showed:

LC_ALL en_US.UTF8

Generally it is a better idea to cut and paste from command line output or a text file then show a screenshot. For the reason above and also because screenshots make it difficult for other users to cut and paste into their machines for testing/debugging purposes.

Back to the problem at hand. The error message only shows up in the section I quoted before with regards to locale handling on Macs.

Are you having any issues with starting Postgres outside of xcode?


On Sat, Jul 28, 2018 at 7:41 PM Adrian Klaver <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>> wrote:

    On 07/28/2018 04:04 AM, Sumit Chaturvedi wrote:
     > Hello everyone. I'm a third year student from IIT Bombay, India.
    Since
     > I'm currently learning about databases, I wanted to debug postgresql
     > with xcode. However, I am having a lot of problems.
     > OS - 10.13.6 (High Sierra)
     > Xcode - 9.4.1
     >
     > To set up my system, I tried to replicate the instructions found at
     > https://wiki.postgresql.org/wiki/Working_with_Eclipse
     > <https://wiki.postgresql.org/wiki/Working_with_Eclipse> for my case.
     >
     > Everything proceeded fine until a point where I had to change the
    run
     > configuration (scheme in xcode terms). I set the executable as
    postgre
     > from /src/backend and gave the appropriate arguments. Then, when I
     > pressed run, I got an error as shown in the attachment.

    I can tell you where the error comes from:

    postmaster.c

    /*
    * On macOS, libintl replaces setlocale() with a version that calls
    * CFLocaleCopyCurrent() when its second argument is "" and every
    relevant
    * environment variable is unset or empty.  CFLocaleCopyCurrent() makes
    * the process multithreaded.  The postmaster calls sigprocmask() and
    * calls fork() without an immediate exec(), both of which have undefined
    * behavior in a multithreaded program.  A multithreaded postmaster
    is the
    * normal case on Windows, which offers neither fork() nor sigprocmask().
    */
    if (pthread_is_threaded_np() != 0)
          ereport(FATAL,
                              (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                              errmsg("postmaster became multithreaded
    during
    startup"),
                              errhint("Set the LC_ALL environment
    variable to
    a valid locale.")));

     > To solve it, I set up my environment variables in xcode
    appropriately to
     > make sure that locale information was reaching wherever it was
    needed.
     > But even now, when I press run I get the same error.

    I do not see that the LC_ALL environment variable is set, per the HINT
    to the FATAL message.

     >
     > Hoping someone can share with me how they went about with their
    setup.
     >
     > --
     > Sumit Chaturvedi


    --     Adrian Klaver
    adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>

--
Sumit Chaturvedi


--
Adrian Klaver
adrian.klaver@aklaver.com



--
Sumit Chaturvedi

Re: postgres with xcode

От
Adrian Klaver
Дата:
On 07/28/2018 11:08 AM, Sumit Chaturvedi wrote:
> Hello.
> 
> Thanks for those pointers. Will keep them in mind in the future. No, 
> there is no problem outside Postgres.

So you can start the Postgres server and use it from a program other 
then xcode?

> 
> Could it be that postmaster becomes multithreaded for some other reason??

That error message only shows up in one place in the code and that is 
when dealing with Mac locales.

You can download the source from here:

https://www.postgresql.org/ftp/source/

and look for yourself.





-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: postgres with xcode

От
Sumit Chaturvedi
Дата:
Yes, I can start Postgres server from the terminal. I was thinking, if I comment out these lines and another assert later on which checks whether postmaster is using multiple threads, I'll be fine right?


On Sat, Jul 28, 2018 at 11:46 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 07/28/2018 11:08 AM, Sumit Chaturvedi wrote:
Hello.

Thanks for those pointers. Will keep them in mind in the future. No, there is no problem outside Postgres.

So you can start the Postgres server and use it from a program other then xcode?


Could it be that postmaster becomes multithreaded for some other reason??

That error message only shows up in one place in the code and that is when dealing with Mac locales.

You can download the source from here:

https://www.postgresql.org/ftp/source/

and look for yourself.





--
Adrian Klaver
adrian.klaver@aklaver.com



--
Sumit Chaturvedi

Re: postgres with xcode

От
Adrian Klaver
Дата:
On 07/28/2018 11:24 AM, Sumit Chaturvedi wrote:
Ccing list
> Yes, I can start Postgres server from the terminal. I was thinking, if I 
> comment out these lines and another assert later on which checks whether 
> postmaster is using multiple threads, I'll be fine right?

If by fine you mean driving further into the crash then yes. The error 
is FATAL for a reason, to stop the postmaster before you do damage.

The issue seems to be with xcode, that is where you should spend your 
time troubleshooting. If it where me I would start by not setting the 
environment variables in xcode. Further help may involve going to an 
xcode mailing list/forum and asking advice.

> 
> On Sat, Jul 28, 2018 at 11:46 PM, Adrian Klaver 
> <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>> wrote:
> 
>     On 07/28/2018 11:08 AM, Sumit Chaturvedi wrote:
> 
>         Hello.
> 
>         Thanks for those pointers. Will keep them in mind in the future.
>         No, there is no problem outside Postgres.
> 
> 
>     So you can start the Postgres server and use it from a program other
>     then xcode?
> 
> 
>         Could it be that postmaster becomes multithreaded for some other
>         reason??
> 
> 
>     That error message only shows up in one place in the code and that
>     is when dealing with Mac locales.
> 
>     You can download the source from here:
> 
>     https://www.postgresql.org/ftp/source/
>     <https://www.postgresql.org/ftp/source/>
> 
>     and look for yourself.
> 
> 
> 
> 
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 
> 
> 
> 
> -- 
> Sumit Chaturvedi


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: postgres with xcode

От
Sumit Chaturvedi
Дата:
Hello,

Does the following seem unusual?

amaltaas:backend amaltaas$ locale

LANG="en_US.UTF-8"

LC_COLLATE="en_US.UTF-8"

LC_CTYPE="en_US.UTF-8"

LC_MESSAGES="en_US.UTF-8"

LC_MONETARY="en_US.UTF-8"

LC_NUMERIC="en_US.UTF-8"

LC_TIME="en_US.UTF-8"

LC_ALL=

After this I ran postgres from terminal like the following and it works:

amaltaas:backend amaltaas$ ./postgres -D ~/Desktop/dn

2018-07-29 14:27:04.544 IST [68250] LOG:  listening on IPv6 address "::1", port 5432

2018-07-29 14:27:04.545 IST [68250] LOG:  listening on IPv6 address "fe80::1%lo0", port 5432

2018-07-29 14:27:04.545 IST [68250] LOG:  listening on IPv4 address "127.0.0.1", port 5432

2018-07-29 14:27:04.546 IST [68250] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

2018-07-29 14:27:04.567 IST [68251] LOG:  database system was shut down at 2018-07-29 14:23:35 IST

2018-07-29 14:27:04.574 IST [68250] LOG:  database system is ready to accept connections

So although the problem is with xcode. I have a feeling that it is not because of LC_ALL.
So my point is that maybe the hint is not entirely correct.. 


On Sun, Jul 29, 2018 at 12:11 AM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 07/28/2018 11:24 AM, Sumit Chaturvedi wrote:
Ccing list
Yes, I can start Postgres server from the terminal. I was thinking, if I comment out these lines and another assert later on which checks whether postmaster is using multiple threads, I'll be fine right?

If by fine you mean driving further into the crash then yes. The error is FATAL for a reason, to stop the postmaster before you do damage.

The issue seems to be with xcode, that is where you should spend your time troubleshooting. If it where me I would start by not setting the environment variables in xcode. Further help may involve going to an xcode mailing list/forum and asking advice.


On Sat, Jul 28, 2018 at 11:46 PM, Adrian Klaver <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>> wrote:

    On 07/28/2018 11:08 AM, Sumit Chaturvedi wrote:

        Hello.

        Thanks for those pointers. Will keep them in mind in the future.
        No, there is no problem outside Postgres.


    So you can start the Postgres server and use it from a program other
    then xcode?


        Could it be that postmaster becomes multithreaded for some other
        reason??


    That error message only shows up in one place in the code and that
    is when dealing with Mac locales.

    You can download the source from here:

    https://www.postgresql.org/ftp/source/
    <https://www.postgresql.org/ftp/source/>

    and look for yourself.





    --     Adrian Klaver
    adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>




--
Sumit Chaturvedi


--
Adrian Klaver
adrian.klaver@aklaver.com



--
Sumit Chaturvedi

Re: postgres with xcode

От
Adrian Klaver
Дата:
On 07/29/2018 02:03 AM, Sumit Chaturvedi wrote:
> Hello,
> 
> Does the following seem unusual?
> 
> amaltaas:backend amaltaas$ locale
> 
> LANG="en_US.UTF-8"
> 
> LC_COLLATE="en_US.UTF-8"
> 
> LC_CTYPE="en_US.UTF-8"
> 
> LC_MESSAGES="en_US.UTF-8"
> 
> LC_MONETARY="en_US.UTF-8"
> 
> LC_NUMERIC="en_US.UTF-8"
> 
> LC_TIME="en_US.UTF-8"
> 
> LC_ALL=
> 
> 
> After this I ran postgres from terminal like the following and it works:
> 
> amaltaas:backend amaltaas$ ./postgres -D ~/Desktop/dn
> 
> 2018-07-29 14:27:04.544 IST [68250] LOG:listening on IPv6 address "::1", 
> port 5432
> 
> 2018-07-29 14:27:04.545 IST [68250] LOG:listening on IPv6 address 
> "fe80::1%lo0", port 5432
> 
> 2018-07-29 14:27:04.545 IST [68250] LOG:listening on IPv4 address 
> "127.0.0.1", port 5432
> 
> 2018-07-29 14:27:04.546 IST [68250] LOG:listening on Unix socket 
> "/tmp/.s.PGSQL.5432"
> 
> 2018-07-29 14:27:04.567 IST [68251] LOG:database system was shut down at 
> 2018-07-29 14:23:35 IST
> 
> 2018-07-29 14:27:04.574 IST [68250] LOG:database system is ready to 
> accept connections
> 
> 
> So although the problem is with xcode. I have a feeling that it is not 
> because of LC_ALL.
> So my point is that maybe the hint is not entirely correct..

Could be, it is a hint not a requirement. Have you tried unsetting the 
LC_ALL variable in xcode?


-- 
Adrian Klaver
adrian.klaver@aklaver.com


Re: postgres with xcode

От
Tom Lane
Дата:
Sumit Chaturvedi <sumit.chaturvedi@gmail.com> writes:
> So although the problem is with xcode. I have a feeling that it is not
> because of LC_ALL.
> So my point is that maybe the hint is not entirely correct..

At the time that HINT was written, the only reason we knew of for a
production postmaster to become multithreaded under macOS was for libintl
to start an extra thread while trying to find out the default locale.
That could be prevented by setting LC_ALL, hence the hint.

I wonder whether starting the postmaster under xcode inherently
causes extra threads to be present (for debugging?).  There are
quite a number of PG developers who use Macs, including me, but
I don't use xcode for PG and I think others don't either.

In any case, I concur with the upthread advice not to take out
the anti-multithreading check.  The postmaster will not work
reliably if there are extra threads in it, so you'd just be
dooming yourself to crashes and frustration.

Usually the thing you want to trace is not the postmaster anyway,
but some session backend.  The best bet is to start the postmaster
normally, start psql or your other client of choice, then identify
which backend process is connected to that client and attach to it
with gdb/lldb.  Perhaps xcode can do an "attach to running process",
though at this point I'm wondering if it starts extra threads when
it does so.

            regards, tom lane


Re: postgres with xcode

От
Sumit Chaturvedi
Дата:
Thanks a lot for spending time to write all these elaborate answers. They were all really helpful. Finally I gave up on xcode and switched to eclipse. Probably for the best.
I was attempting to do all this in the first place because in our course in college, we have to do a project. Almost all people make a web/mobile app which simply uses a database. I felt that this wasn't a right project to do if one really wanted to learn about databases. 
So I wanted to play around with Postgresql itself. I have looked at the TODO list and it has given me a lot of ideas. If anyone has any thoughts/ideas which they didn't have time to pursue but are interesting, please let me know?

With warm regards

On Sun, Jul 29, 2018 at 8:06 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Sumit Chaturvedi <sumit.chaturvedi@gmail.com> writes:
> So although the problem is with xcode. I have a feeling that it is not
> because of LC_ALL.
> So my point is that maybe the hint is not entirely correct..

At the time that HINT was written, the only reason we knew of for a
production postmaster to become multithreaded under macOS was for libintl
to start an extra thread while trying to find out the default locale.
That could be prevented by setting LC_ALL, hence the hint.

I wonder whether starting the postmaster under xcode inherently
causes extra threads to be present (for debugging?).  There are
quite a number of PG developers who use Macs, including me, but
I don't use xcode for PG and I think others don't either.

In any case, I concur with the upthread advice not to take out
the anti-multithreading check.  The postmaster will not work
reliably if there are extra threads in it, so you'd just be
dooming yourself to crashes and frustration.

Usually the thing you want to trace is not the postmaster anyway,
but some session backend.  The best bet is to start the postmaster
normally, start psql or your other client of choice, then identify
which backend process is connected to that client and attach to it
with gdb/lldb.  Perhaps xcode can do an "attach to running process",
though at this point I'm wondering if it starts extra threads when
it does so.

                        regards, tom lane



--
Sumit Chaturvedi

Re: postgres with xcode

От
Tom Lane
Дата:
Sumit Chaturvedi <sumit.chaturvedi@gmail.com> writes:
> So I wanted to play around with Postgresql itself. I have looked at the
> TODO list and it has given me a lot of ideas. If anyone has any
> thoughts/ideas which they didn't have time to pursue but are interesting,
> please let me know?

Cool, but be warned that most of the stuff on the TODO list is either
obsolete or hard (sometimes more hard-to-get-consensus-for than hard-
to-do-technically).  We don't maintain that list very well :-(

            regards, tom lane


Re: postgres with xcode

От
Sumit Chaturvedi
Дата:
Well in that case, do you have something in mind. Perhaps a prototype which has a some research component which can teach us something interesting. In the course we are divided into teams of 4 and we are going to work on the project for 2-3 months. I know such I'm asking for too much but just giving it a shot really. :)

On Sun, Jul 29, 2018 at 9:26 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Sumit Chaturvedi <sumit.chaturvedi@gmail.com> writes:
> So I wanted to play around with Postgresql itself. I have looked at the
> TODO list and it has given me a lot of ideas. If anyone has any
> thoughts/ideas which they didn't have time to pursue but are interesting,
> please let me know?

Cool, but be warned that most of the stuff on the TODO list is either
obsolete or hard (sometimes more hard-to-get-consensus-for than hard-
to-do-technically).  We don't maintain that list very well :-(

                        regards, tom lane
--
Sumit Chaturvedi