@@ -242,6 +242,12 @@ private void initdb()
242
242
final StopWatch watch = new StopWatch ();
243
243
watch .start ();
244
244
List <String > command = new ArrayList <>();
245
+ if (SystemUtils .IS_OS_LINUX ) {
246
+ Long uid = new com .sun .security .auth .module .UnixSystem ().getUid ();
247
+ if (uid == 0 ) {
248
+ command .addAll (Arrays .asList ("unshare" , "-Uu" ));
249
+ }
250
+ }
245
251
command .addAll (Arrays .asList (
246
252
pgBin ("initdb" ), "-A" , "trust" , "-U" , PG_SUPERUSER ,
247
253
"-D" , dataDirectory .getPath (), "-E" , "UTF-8" ));
@@ -259,6 +265,12 @@ private void startPostmaster() throws IOException
259
265
}
260
266
261
267
final List <String > args = new ArrayList <>();
268
+ if (SystemUtils .IS_OS_LINUX ) {
269
+ Long uid = new com .sun .security .auth .module .UnixSystem ().getUid ();
270
+ if (uid == 0 ) {
271
+ args .addAll (Arrays .asList ("unshare" , "-Uu" ));
272
+ }
273
+ }
262
274
args .addAll (Arrays .asList (
263
275
pgBin ("pg_ctl" ),
264
276
"-D" , dataDirectory .getPath (),
@@ -414,7 +426,15 @@ public void close() throws IOException
414
426
415
427
private void pgCtl (File dir , String action )
416
428
{
417
- system (pgBin ("pg_ctl" ), "-D" , dir .getPath (), action , "-m" , PG_STOP_MODE , "-t" , PG_STOP_WAIT_S , "-w" );
429
+ final List <String > args = new ArrayList <>();
430
+ if (SystemUtils .IS_OS_LINUX ) {
431
+ Long uid = new com .sun .security .auth .module .UnixSystem ().getUid ();
432
+ if (uid == 0 ) {
433
+ args .addAll (Arrays .asList ("unshare" , "-Uu" ));
434
+ }
435
+ }
436
+ args .addAll (Arrays .asList (pgBin ("pg_ctl" ), "-D" , dir .getPath (), action , "-m" , PG_STOP_MODE , "-t" , PG_STOP_WAIT_S , "-w" ));
437
+ system (args .toArray (new String [args .size ()]));
418
438
}
419
439
420
440
private void cleanOldDataDirectories (File parentDirectory )
@@ -780,7 +800,12 @@ private static File prepareBinaries(PgBinaryResolver pgBinaryResolver, File over
780
800
781
801
String pgDigest = Hex .encodeHexString (pgArchiveData .getMessageDigest ().digest ());
782
802
File workingDirectory = Optional .ofNullable (overrideWorkingDirectory ).orElse (getWorkingDirectory ());
783
- pgDir = new File (workingDirectory , String .format ("PG-%s" , pgDigest ));
803
+ if (SystemUtils .IS_OS_LINUX || SystemUtils .IS_OS_MAC_OSX ) {
804
+ Long uid = new com .sun .security .auth .module .UnixSystem ().getUid ();
805
+ pgDir = new File (workingDirectory , String .format ("PG-%d-%s" , uid , pgDigest ));
806
+ } else {
807
+ pgDir = new File (workingDirectory , String .format ("PG-%s" , pgDigest ));
808
+ }
784
809
785
810
mkdirs (pgDir );
786
811
final File unpackLockFile = new File (pgDir , LOCK_FILE_NAME );
0 commit comments