# Cannot initialize postgresql



## mefizto (Jan 29, 2020)

Greetings all,

after successful installation and enabling PostgreSQL service to start on system boot:

```
sysrc postgresql_enable=yes
```
the database initiation fails:

```
# /usr/local/etc/rc.d/postgresql initdb
/usr/local/etc/rc.d/postgresql: Permission denied
```

Any help would be appreciated.

Kindest regards,

M


----------



## msplsh (Jan 29, 2020)

sudo?


----------



## mefizto (Jan 29, 2020)

Hi msplsh,

Can you elaborate please?

Kindest regards,

M


----------



## msplsh (Jan 29, 2020)

You probably can't initialize the database as the non-database or non-root user.


----------



## mefizto (Jan 29, 2020)

Hi msplsh,

but I am trying to initialize the database as a root.

Kindest regards,

M


----------



## msplsh (Jan 29, 2020)

Missing execute bit on /usr/local/etc/rc.d/postgresql ?


----------



## mefizto (Jan 29, 2020)

Hi msplsh,

thank you very much for trying to help.  

As to your question, no I do have the execuiton bit set.  I was trying to trace the problem, so I ran the command as:


```
# sh -x /usr/local/etc/rc.d/postgresql initdb
```

which worked.  So, now I am even more confused.

Kindest regards,

M


----------



## drhowarddrfine (Jan 29, 2020)

Be careful as I think you are using the instructions from PostgreSQL's web site. iirc, there are Linux-isms there to avoid but there  are FreeBSD instructions available which are slightly different. 
It's been a long time since I've done this so I can't be much help (though I'll be restarting a pgsql project shortly myself).


----------



## SirDice (Jan 29, 2020)

Please post the output from `ls -l /usr/local/etc/rc.d/postgresql`


----------



## mefizto (Jan 29, 2020)

Hi drhowarddrfine,

the instructions were copied from the notes upon finishing installation, so I do not think that they were copied for Linux.  In fact, Linux uses a different file structure for the different components of the application.

Hi SirDice.


```
$ ls -l /usr/local/etc/rc.d/postgresql
-r-xr-xr-x 1 root wheel 3346 Dec 30 21:33 /usr/local/etc/rc.d/postgresql
```

What really confuses me is why the `sh -x`command works.  From the sh(), the `-x`option:

```
xtrace
         Write each    command    (preceded by the value of the [I]PS4[/I] variable
         subjected to parameter expansion and arithmetic expansion)    to
         standard error before it is executed.  Useful for debugging.
```
Kindest regards,

M


----------

