Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 351079

Summary: emerge --config dev-db/postgresql-server fail on a new dedicated ext3 partition (partition not empty)
Product: Gentoo Linux Reporter: Alain Toussaint <atoussaint76>
Component: [OLD] ServerAssignee: PgSQL Bugs <pgsql-bugs>
Status: RESOLVED FIXED    
Severity: minor CC: jmbsvicetto, titanofold
Priority: High    
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Alain Toussaint 2011-01-08 04:00:05 UTC
I created a dedicated partition for PGDATA on a 80GB hard disk but emerge --config dev-db/postgresql-server fail because the disk is not empty and contain the lost&found directory.

Reproducible: Always

Steps to Reproduce:
1. cfdisk /dev/sdb, create new partition /dev/sdb1
2. mke2fs -j /dev/sdb1 (ext3)
3. edit /etc/fstab to mount the new partition (on /pgdata, options: data=ordered,barrier=1)
4. mount the new partition, chown -R postgres:postgres /pgdata
5. edit /etc/conf.d/postgresql-9.0
6. emerge --config dev-db/postgresql-server
Actual Results:  
 * Checking system parameters...
 * Checking whether your system supports at least 128 connections...
 * Passed.
 * Creating the data directory ...
 * Initializing the database ...
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale fr_CA.utf8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "french".

initdb: directory "/pgdata" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/pgdata" or run initdb
with an argument other than "/pgdata".


Expected Results:  
not barf on the lost&found directory.

I removed the lost&found directory, reran emerge --config dev-db/postgresql-server and finally, ran mklost&found in the /pgdata directory to fix the problem.

Portage 2.1.9.28 (default/linux/x86/10.0/server, gcc-4.5.2, glibc-2.12.1-r3, 2.6.36-gentoo-r6 i686)
=================================================================
System uname: Linux-2.6.36-gentoo-r6-i686-Intel-R-_Pentium-R-_4_CPU_2.00GHz-with-gentoo-2.0.1
Timestamp of tree: Mon, 03 Jan 2011 17:45:01 +0000
app-shells/bash:     4.1_p9
dev-java/java-config: 2.1.11-r3
dev-lang/python:     2.7.1, 3.1.3
dev-util/cmake:      2.8.3-r1
sys-apps/baselayout: 2.0.1-r1
sys-apps/openrc:     0.6.8
sys-apps/sandbox:    2.4
sys-devel/autoconf:  2.68
sys-devel/automake:  1.10.3, 1.11.1
sys-devel/binutils:  2.21
sys-devel/gcc:       4.5.2
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.4-r1
sys-devel/make:      3.82
virtual/os-headers:  2.6.36.1 (sys-kernel/linux-headers)
ACCEPT_KEYWORDS="x86 ~x86"
ACCEPT_LICENSE="*"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-Os -march=native -mtune=native -msse -msse2 -mfpmath=sse -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/eselect/postgresql /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-Os -march=native -mtune=native -msse -msse2 -mfpmath=sse -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="assume-digests binpkg-logs distlocks fixlafiles fixpackages news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
GENTOO_MIRRORS="http://gentoo.gossamerhost.com http://mirror.csclub.uwaterloo.ca/gentoo-distfiles/"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="fr"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://rsync.ca.gentoo.org/gentoo-portage"
USE="acl bash-completion bzip2 caps cli cracklib crypt cups cxx dbus dri extras fam gd gdbm gmp gpm iconv icu jbig jpeg jpeg2k libedit mmx modules mono mudflap ncurses nls nptl nptlonly nss objc objc++ objc-gc openmp pam pcre pic png postgres pppd python readline servletapi session slp snmp sqlite sse sse2 ssl symlink sysfs tcpd threads tiff truetype unicode unlock-notify x86 xattr xml xorg zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_default authz_groupfile authz_host authz_owner authz_user autoindex deflate dir disk_cache env expires ext_filter file_cache cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias cgid" APACHE2_MPMS="event" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="fr" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="fbdev glint intel mach64 mga neomagic nouveau nv r128 radeon savage sis tdfx trident vesa via vmware dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LANG, LC_ALL, MAKEOPTS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PORTDIR_OVERLAY

/etc/fstab:

# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't
# needed; notail increases performance of ReiserFS (at the expense of storage
# efficiency).  It's safe to drop the noatime options if you want and to
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>

# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
/dev/disk/by-uuid/c67857da-f8b2-44c5-bc80-e0062b9f2358          /boot           ext3            noauto,noatime  1 2
/dev/disk/by-uuid/131eef43-793e-43c8-b856-bb0caf908dea          /               ext3            noatime         0 1
/dev/disk/by-uuid/5f480fcf-5625-41e2-bb4f-5a58e6531d6c          none            swap            sw              0 0
/dev/cdrom              /mnt/cdrom      auto            noauto,ro       0 0
#/dev/fd0               /mnt/floppy     auto            noauto          0 0

# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
# POSIX shared memory (shm_open, shm_unlink).
# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will
#  use almost no memory if not populated with files)
shm                     /dev/shm        tmpfs           nodev,nosuid,noexec     0 0
/dev/disk/by-uuid/e51a08cd-4442-4cde-82f7-3f5d70f83023  /pgdata         ext3    data=ordered,barrier=1          0 1
Comment 1 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2011-01-08 06:35:53 UTC
Instead of mapping the partition to the PGDATA dir, wny don't you create the  PGDATA dir under the new partition?
If postgres works similarly to mysql, it likely won't accept what you're trying to do.
Comment 2 Aaron W. Swenson gentoo-dev 2011-01-08 13:26:37 UTC
This isn't a bug; it's a feature.

initdb won't allow an install to take place where data already exists. It may be a bit heavy handed, but it's easier to program for "if there's anything there" than it is to program for "if any of these files are there".

I'm guessing you edited the PGDATA variable in /etc/conf.d/postgresql-9.0 to contain:

PGDATA="/pgdata"

Instead, go for:

PGDATA="/pgdata/9.0/"

That is the recommended manner as it allows you to know which data belongs to which branch. In this case, /pgdata/9.0/ is PostgreSQL 9.0.x and /pgdata/9.1/ is PostgreSQL 9.1.x.

Furthermore, you're going to have to adjust the 'postgres' Unix account to have it's home relocated to /pgdata/. Or, you could go the easy way and mount the separate partition to /var/lib/postgresql/ and stick with the defaults.
Comment 3 Aaron W. Swenson gentoo-dev 2011-01-08 13:32:07 UTC
(In reply to comment #1)
> Instead of mapping the partition to the PGDATA dir, wny don't you create the 
> PGDATA dir under the new partition?
> If postgres works similarly to mysql, it likely won't accept what you're trying
> to do.
> 

It will certainly allow the reporter to specify where he wants the data directory to be. The directory just need to be empty.
Comment 4 Jorge Manuel B. S. Vicetto (RETIRED) Gentoo Infrastructure gentoo-dev 2011-01-08 13:54:03 UTC
(In reply to comment #3)
> (In reply to comment #1)
> > Instead of mapping the partition to the PGDATA dir, wny don't you create the 
> > PGDATA dir under the new partition?
> > If postgres works similarly to mysql, it likely won't accept what you're trying
> > to do.
> > 
> 
> It will certainly allow the reporter to specify where he wants the data
> directory to be. The directory just need to be empty.

Right, but an ext3 root will never be empty (lost+found).

What I was suggesting is similar to what you said in the previous comment. If the user was trying to use /pgdata, why not have the partition mounted as /pgdata, but tell postgresql to store the files under /pgdata/<something>?
Comment 5 Aaron W. Swenson gentoo-dev 2011-01-08 14:07:48 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #1)
> > > Instead of mapping the partition to the PGDATA dir, wny don't you create the 
> > > PGDATA dir under the new partition?
> > > If postgres works similarly to mysql, it likely won't accept what you're trying
> > > to do.
> > > 
> > 
> > It will certainly allow the reporter to specify where he wants the data
> > directory to be. The directory just need to be empty.
> 
> Right, but an ext3 root will never be empty (lost+found).
> 
> What I was suggesting is similar to what you said in the previous comment. If
> the user was trying to use /pgdata, why not have the partition mounted as
> /pgdata, but tell postgresql to store the files under /pgdata/<something>?
> 

I have a feeling we might be writing past each other.

I wasn't arguing against mounting the partition to /pgdata, only that fewer changes need to be made if it's mounted to /var/lib/postgresql/.

As for making /pgdata a directory on the dedicated partition and then mounting it to /, that may not be such a good idea as it could interfere with /'s lost+found.

As for having initdb automatically install to ${something} regardless of what the system administrator's desires: It is the system administrator's responsibility to determine what's best and work with the software based on its requirements. In this case, initdb requires an empty directory, so it is up to the system administrator to change PGDATA="/pgdata" to PGDATA="/pgdata/${something}" -- or some other solution -- so that initdb will have an empty directory to use.
Comment 6 Alain Toussaint 2011-01-12 06:27:05 UTC
Thanks you very much for the comments. I'll keep postgresql in a directory under /pgdata (/pgdata/9.0), the changes remaining to be done is to adjust pg's home dir to the new location for consistency with my setup (I have a few softwares which I install and they are not available in portage).