summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Exequiel Pedone2024-03-24 21:15:26 -0300
committerGonzalo Exequiel Pedone2024-03-24 21:15:26 -0300
commit6e2123da400781870a23573c27256ec58ba7052d (patch)
treefbd80c57d9028494a164d12a3b5f5c747f194054
downloadaur-6e2123da400781870a23573c27256ec58ba7052d.tar.gz
New package.
-rw-r--r--.SRCINFO43
-rw-r--r--.gitignore6
-rw-r--r--0001-Force-utf8-codeset.patch24
-rw-r--r--0002-Disable-unsupported-functions.patch64
-rw-r--r--0003-Disable-shm.patch751
-rw-r--r--0004-Fix-type-casting.patch38
-rw-r--r--0005-Added-missing-headers.patch10
-rw-r--r--0006-Fix-duplicate-case.patch33
-rw-r--r--0007-Unversioned-libs.patch10
-rw-r--r--PKGBUILD110
10 files changed, 1089 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..b8ff37da0c62
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,43 @@
+pkgbase = android-x86-64-postgresql
+ pkgdesc = Sophisticated object-relational DBMS (Android, x86-64)
+ pkgver = 16.1
+ pkgrel = 1
+ url = https://www.postgresql.org/
+ arch = any
+ license = custom:PostgreSQL
+ makedepends = android-configure
+ makedepends = util-linux
+ makedepends = android-x86-64-tcl
+ makedepends = tcl
+ depends = android-x86-64-icu
+ depends = android-x86-64-openldap
+ depends = android-x86-64-libxml2
+ depends = android-x86-64-libxslt
+ depends = android-x86-64-lz4
+ depends = android-x86-64-openssl
+ depends = android-x86-64-readline
+ depends = android-x86-64-zlib
+ depends = android-x86-64-zstd
+ optdepends = android-x86-64-tcl: for PL/Tcl support
+ options = !strip
+ options = !buildflags
+ options = staticlibs
+ options = !emptydirs
+ source = https://ftp.postgresql.org/pub/source/v16.1/postgresql-16.1.tar.bz2
+ source = 0001-Force-utf8-codeset.patch
+ source = 0002-Disable-unsupported-functions.patch
+ source = 0003-Disable-shm.patch
+ source = 0004-Fix-type-casting.patch
+ source = 0005-Added-missing-headers.patch
+ source = 0006-Fix-duplicate-case.patch
+ source = 0007-Unversioned-libs.patch
+ md5sums = 9cbfb9076ed06384471802b850698a6d
+ md5sums = 4c19ab4024b4079e668117d79a9058b3
+ md5sums = 75dad9c605ab1987c22e5b0da564dccb
+ md5sums = 3305f78f93bed96409971e5ca269314d
+ md5sums = f88a4fb16aef45bbd6f01a912cd7a8fa
+ md5sums = f52a2e35dbb0bf71f4cc553ebd008c10
+ md5sums = d1e8c384acb46460750c1af057449578
+ md5sums = 7bc0f291f718c4fc3181addf7c8d0b14
+
+pkgname = android-x86-64-postgresql
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000000..b5b03b115225
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+pkg
+src
+*.tar.xz
+*.tar.gz
+*.tar.bz2
+*.asc
diff --git a/0001-Force-utf8-codeset.patch b/0001-Force-utf8-codeset.patch
new file mode 100644
index 000000000000..59b6a16a843f
--- /dev/null
+++ b/0001-Force-utf8-codeset.patch
@@ -0,0 +1,24 @@
+--- a/src/port/chklocale.c
++++ b/src/port/chklocale.c
+@@ -335,9 +335,7 @@
+ }
+
+ #ifndef WIN32
+- sys = nl_langinfo(CODESET);
+- if (sys)
+- sys = strdup(sys);
++ sys = strdup("UTF-8");
+ #else
+ sys = win32_langinfo(name);
+ #endif
+@@ -358,9 +356,7 @@
+ return PG_SQL_ASCII;
+
+ #ifndef WIN32
+- sys = nl_langinfo(CODESET);
+- if (sys)
+- sys = strdup(sys);
++ sys = strdup("UTF-8");
+ #else
+ sys = win32_langinfo(ctype);
+ #endif
diff --git a/0002-Disable-unsupported-functions.patch b/0002-Disable-unsupported-functions.patch
new file mode 100644
index 000000000000..aca19b693c47
--- /dev/null
+++ b/0002-Disable-unsupported-functions.patch
@@ -0,0 +1,64 @@
+--- a/src/backend/libpq/be-secure-openssl.c
++++ b/src/backend/libpq/be-secure-openssl.c
+@@ -973,61 +973,11 @@
+ static DH *
+ load_dh_file(char *filename, bool isServerStart)
+ {
+- FILE *fp;
+- DH *dh = NULL;
+- int codes;
+-
+- /* attempt to open file. It's not an error if it doesn't exist. */
+- if ((fp = AllocateFile(filename, "r")) == NULL)
+- {
+- ereport(isServerStart ? FATAL : LOG,
+- (errcode_for_file_access(),
+- errmsg("could not open DH parameters file \"%s\": %m",
+- filename)));
+- return NULL;
+- }
+-
+- dh = PEM_read_DHparams(fp, NULL, NULL, NULL);
+- FreeFile(fp);
+-
+- if (dh == NULL)
+- {
+ ereport(isServerStart ? FATAL : LOG,
+ (errcode(ERRCODE_CONFIG_FILE_ERROR),
+ errmsg("could not load DH parameters file: %s",
+ SSLerrmessage(ERR_get_error()))));
+ return NULL;
+- }
+-
+- /* make sure the DH parameters are usable */
+- if (DH_check(dh, &codes) == 0)
+- {
+- ereport(isServerStart ? FATAL : LOG,
+- (errcode(ERRCODE_CONFIG_FILE_ERROR),
+- errmsg("invalid DH parameters: %s",
+- SSLerrmessage(ERR_get_error()))));
+- DH_free(dh);
+- return NULL;
+- }
+- if (codes & DH_CHECK_P_NOT_PRIME)
+- {
+- ereport(isServerStart ? FATAL : LOG,
+- (errcode(ERRCODE_CONFIG_FILE_ERROR),
+- errmsg("invalid DH parameters: p is not prime")));
+- DH_free(dh);
+- return NULL;
+- }
+- if ((codes & DH_NOT_SUITABLE_GENERATOR) &&
+- (codes & DH_CHECK_P_NOT_SAFE_PRIME))
+- {
+- ereport(isServerStart ? FATAL : LOG,
+- (errcode(ERRCODE_CONFIG_FILE_ERROR),
+- errmsg("invalid DH parameters: neither suitable generator or safe prime")));
+- DH_free(dh);
+- return NULL;
+- }
+-
+- return dh;
+ }
+
+ /*
diff --git a/0003-Disable-shm.patch b/0003-Disable-shm.patch
new file mode 100644
index 000000000000..a5bcb44368d3
--- /dev/null
+++ b/0003-Disable-shm.patch
@@ -0,0 +1,751 @@
+--- a/src/backend/port/sysv_shmem.c
++++ b/src/backend/port/sysv_shmem.c
+@@ -119,161 +119,7 @@
+ static void *
+ InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
+ {
+- IpcMemoryId shmid;
+- void *requestedAddress = NULL;
+- void *memAddress;
+-
+- /*
+- * Normally we just pass requestedAddress = NULL to shmat(), allowing the
+- * system to choose where the segment gets mapped. But in an EXEC_BACKEND
+- * build, it's possible for whatever is chosen in the postmaster to not
+- * work for backends, due to variations in address space layout. As a
+- * rather klugy workaround, allow the user to specify the address to use
+- * via setting the environment variable PG_SHMEM_ADDR. (If this were of
+- * interest for anything except debugging, we'd probably create a cleaner
+- * and better-documented way to set it, such as a GUC.)
+- */
+-#ifdef EXEC_BACKEND
+- {
+- char *pg_shmem_addr = getenv("PG_SHMEM_ADDR");
+-
+- if (pg_shmem_addr)
+- requestedAddress = (void *) strtoul(pg_shmem_addr, NULL, 0);
+- else
+- {
+-#if defined(__darwin__) && SIZEOF_VOID_P == 8
+- /*
+- * Provide a default value that is believed to avoid problems with
+- * ASLR on the current macOS release.
+- */
+- requestedAddress = (void *) 0x80000000000;
+-#endif
+- }
+- }
+-#endif
+-
+- shmid = shmget(memKey, size, IPC_CREAT | IPC_EXCL | IPCProtection);
+-
+- if (shmid < 0)
+- {
+- int shmget_errno = errno;
+-
+- /*
+- * Fail quietly if error indicates a collision with existing segment.
+- * One would expect EEXIST, given that we said IPC_EXCL, but perhaps
+- * we could get a permission violation instead? Also, EIDRM might
+- * occur if an old seg is slated for destruction but not gone yet.
+- */
+- if (shmget_errno == EEXIST || shmget_errno == EACCES
+-#ifdef EIDRM
+- || shmget_errno == EIDRM
+-#endif
+- )
+- return NULL;
+-
+- /*
+- * Some BSD-derived kernels are known to return EINVAL, not EEXIST, if
+- * there is an existing segment but it's smaller than "size" (this is
+- * a result of poorly-thought-out ordering of error tests). To
+- * distinguish between collision and invalid size in such cases, we
+- * make a second try with size = 0. These kernels do not test size
+- * against SHMMIN in the preexisting-segment case, so we will not get
+- * EINVAL a second time if there is such a segment.
+- */
+- if (shmget_errno == EINVAL)
+- {
+- shmid = shmget(memKey, 0, IPC_CREAT | IPC_EXCL | IPCProtection);
+-
+- if (shmid < 0)
+- {
+- /* As above, fail quietly if we verify a collision */
+- if (errno == EEXIST || errno == EACCES
+-#ifdef EIDRM
+- || errno == EIDRM
+-#endif
+- )
+ return NULL;
+- /* Otherwise, fall through to report the original error */
+- }
+- else
+- {
+- /*
+- * On most platforms we cannot get here because SHMMIN is
+- * greater than zero. However, if we do succeed in creating a
+- * zero-size segment, free it and then fall through to report
+- * the original error.
+- */
+- if (shmctl(shmid, IPC_RMID, NULL) < 0)
+- elog(LOG, "shmctl(%d, %d, 0) failed: %m",
+- (int) shmid, IPC_RMID);
+- }
+- }
+-
+- /*
+- * Else complain and abort.
+- *
+- * Note: at this point EINVAL should mean that either SHMMIN or SHMMAX
+- * is violated. SHMALL violation might be reported as either ENOMEM
+- * (BSDen) or ENOSPC (Linux); the Single Unix Spec fails to say which
+- * it should be. SHMMNI violation is ENOSPC, per spec. Just plain
+- * not-enough-RAM is ENOMEM.
+- */
+- errno = shmget_errno;
+- ereport(FATAL,
+- (errmsg("could not create shared memory segment: %m"),
+- errdetail("Failed system call was shmget(key=%lu, size=%zu, 0%o).",
+- (unsigned long) memKey, size,
+- IPC_CREAT | IPC_EXCL | IPCProtection),
+- (shmget_errno == EINVAL) ?
+- errhint("This error usually means that PostgreSQL's request for a shared memory "
+- "segment exceeded your kernel's SHMMAX parameter, or possibly that "
+- "it is less than "
+- "your kernel's SHMMIN parameter.\n"
+- "The PostgreSQL documentation contains more information about shared "
+- "memory configuration.") : 0,
+- (shmget_errno == ENOMEM) ?
+- errhint("This error usually means that PostgreSQL's request for a shared "
+- "memory segment exceeded your kernel's SHMALL parameter. You might need "
+- "to reconfigure the kernel with larger SHMALL.\n"
+- "The PostgreSQL documentation contains more information about shared "
+- "memory configuration.") : 0,
+- (shmget_errno == ENOSPC) ?
+- errhint("This error does *not* mean that you have run out of disk space. "
+- "It occurs either if all available shared memory IDs have been taken, "
+- "in which case you need to raise the SHMMNI parameter in your kernel, "
+- "or because the system's overall limit for shared memory has been "
+- "reached.\n"
+- "The PostgreSQL documentation contains more information about shared "
+- "memory configuration.") : 0));
+- }
+-
+- /* Register on-exit routine to delete the new segment */
+- on_shmem_exit(IpcMemoryDelete, Int32GetDatum(shmid));
+-
+- /* OK, should be able to attach to the segment */
+- memAddress = shmat(shmid, requestedAddress, PG_SHMAT_FLAGS);
+-
+- if (memAddress == (void *) -1)
+- elog(FATAL, "shmat(id=%d, addr=%p, flags=0x%x) failed: %m",
+- shmid, requestedAddress, PG_SHMAT_FLAGS);
+-
+- /* Register on-exit routine to detach new segment before deleting */
+- on_shmem_exit(IpcMemoryDetach, PointerGetDatum(memAddress));
+-
+- /*
+- * Store shmem key and ID in data directory lockfile. Format to try to
+- * keep it the same length always (trailing junk in the lockfile won't
+- * hurt, but might confuse humans).
+- */
+- {
+- char line[64];
+-
+- sprintf(line, "%9lu %9lu",
+- (unsigned long) memKey, (unsigned long) shmid);
+- AddToDataDirLockFile(LOCK_FILE_LINE_SHMEM_KEY, line);
+- }
+-
+- return memAddress;
+ }
+
+ /****************************************************************************/
+@@ -285,7 +131,6 @@
+ IpcMemoryDetach(int status, Datum shmaddr)
+ {
+ /* Detach System V shared memory block. */
+- if (shmdt((void *) DatumGetPointer(shmaddr)) < 0)
+ elog(LOG, "shmdt(%p) failed: %m", DatumGetPointer(shmaddr));
+ }
+
+@@ -296,7 +141,6 @@
+ static void
+ IpcMemoryDelete(int status, Datum shmId)
+ {
+- if (shmctl(DatumGetInt32(shmId), IPC_RMID, NULL) < 0)
+ elog(LOG, "shmctl(%d, %d, 0) failed: %m",
+ DatumGetInt32(shmId), IPC_RMID);
+ }
+@@ -315,23 +159,8 @@
+ bool
+ PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
+ {
+- PGShmemHeader *memAddress;
+- IpcMemoryState state;
+-
+- state = PGSharedMemoryAttach((IpcMemoryId) id2, NULL, &memAddress);
+- if (memAddress && shmdt((void *) memAddress) < 0)
+- elog(LOG, "shmdt(%p) failed: %m", memAddress);
+- switch (state)
+- {
+- case SHMSTATE_ENOENT:
+- case SHMSTATE_FOREIGN:
+- case SHMSTATE_UNATTACHED:
++ elog(LOG, "shmdt(%p) failed: %m", NULL);
+ return false;
+- case SHMSTATE_ANALYSIS_FAILURE:
+- case SHMSTATE_ATTACHED:
+- return true;
+- }
+- return true;
+ }
+
+ /*
+@@ -347,109 +176,9 @@
+ void *attachAt,
+ PGShmemHeader **addr)
+ {
+- struct shmid_ds shmStat;
+- struct stat statbuf;
+- PGShmemHeader *hdr;
+-
+ *addr = NULL;
+
+- /*
+- * First, try to stat the shm segment ID, to see if it exists at all.
+- */
+- if (shmctl(shmId, IPC_STAT, &shmStat) < 0)
+- {
+- /*
+- * EINVAL actually has multiple possible causes documented in the
+- * shmctl man page, but we assume it must mean the segment no longer
+- * exists.
+- */
+- if (errno == EINVAL)
+- return SHMSTATE_ENOENT;
+-
+- /*
+- * EACCES implies we have no read permission, which means it is not a
+- * Postgres shmem segment (or at least, not one that is relevant to
+- * our data directory).
+- */
+- if (errno == EACCES)
+ return SHMSTATE_FOREIGN;
+-
+- /*
+- * Some Linux kernel versions (in fact, all of them as of July 2007)
+- * sometimes return EIDRM when EINVAL is correct. The Linux kernel
+- * actually does not have any internal state that would justify
+- * returning EIDRM, so we can get away with assuming that EIDRM is
+- * equivalent to EINVAL on that platform.
+- */
+-#ifdef HAVE_LINUX_EIDRM_BUG
+- if (errno == EIDRM)
+- return SHMSTATE_ENOENT;
+-#endif
+-
+- /*
+- * Otherwise, we had better assume that the segment is in use. The
+- * only likely case is (non-Linux, assumed spec-compliant) EIDRM,
+- * which implies that the segment has been IPC_RMID'd but there are
+- * still processes attached to it.
+- */
+- return SHMSTATE_ANALYSIS_FAILURE;
+- }
+-
+- /*
+- * Try to attach to the segment and see if it matches our data directory.
+- * This avoids any risk of duplicate-shmem-key conflicts on machines that
+- * are running several postmasters under the same userid.
+- *
+- * (When we're called from PGSharedMemoryCreate, this stat call is
+- * duplicative; but since this isn't a high-traffic case it's not worth
+- * trying to optimize.)
+- */
+- if (stat(DataDir, &statbuf) < 0)
+- return SHMSTATE_ANALYSIS_FAILURE; /* can't stat; be conservative */
+-
+- hdr = (PGShmemHeader *) shmat(shmId, attachAt, PG_SHMAT_FLAGS);
+- if (hdr == (PGShmemHeader *) -1)
+- {
+- /*
+- * Attachment failed. The cases we're interested in are the same as
+- * for the shmctl() call above. In particular, note that the owning
+- * postmaster could have terminated and removed the segment between
+- * shmctl() and shmat().
+- *
+- * If attachAt isn't NULL, it's possible that EINVAL reflects a
+- * problem with that address not a vanished segment, so it's best to
+- * pass NULL when probing for conflicting segments.
+- */
+- if (errno == EINVAL)
+- return SHMSTATE_ENOENT; /* segment disappeared */
+- if (errno == EACCES)
+- return SHMSTATE_FOREIGN; /* must be non-Postgres */
+-#ifdef HAVE_LINUX_EIDRM_BUG
+- if (errno == EIDRM)
+- return SHMSTATE_ENOENT; /* segment disappeared */
+-#endif
+- /* Otherwise, be conservative. */
+- return SHMSTATE_ANALYSIS_FAILURE;
+- }
+- *addr = hdr;
+-
+- if (hdr->magic != PGShmemMagic ||
+- hdr->device != statbuf.st_dev ||
+- hdr->inode != statbuf.st_ino)
+- {
+- /*
+- * It's either not a Postgres segment, or not one for my data
+- * directory.
+- */
+- return SHMSTATE_FOREIGN;
+- }
+-
+- /*
+- * It does match our data directory, so now test whether any processes are
+- * still attached to it. (We are, now, but the shm_nattch result is from
+- * before we attached to it.)
+- */
+- return shmStat.shm_nattch == 0 ? SHMSTATE_UNATTACHED : SHMSTATE_ATTACHED;
+ }
+
+ /*
+@@ -691,170 +420,8 @@
+ PGSharedMemoryCreate(Size size,
+ PGShmemHeader **shim)
+ {
+- IpcMemoryKey NextShmemSegID;
+- void *memAddress;
+- PGShmemHeader *hdr;
+- struct stat statbuf;
+- Size sysvsize;
+-
+- /*
+- * We use the data directory's ID info (inode and device numbers) to
+- * positively identify shmem segments associated with this data dir, and
+- * also as seeds for searching for a free shmem key.
+- */
+- if (stat(DataDir, &statbuf) < 0)
+- ereport(FATAL,
+- (errcode_for_file_access(),
+- errmsg("could not stat data directory \"%s\": %m",
+- DataDir)));
+-
+- /* Complain if hugepages demanded but we can't possibly support them */
+-#if !defined(MAP_HUGETLB)
+- if (huge_pages == HUGE_PAGES_ON)
+- ereport(ERROR,
+- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+- errmsg("huge pages not supported on this platform")));
+-#endif
+-
+- /* For now, we don't support huge pages in SysV memory */
+- if (huge_pages == HUGE_PAGES_ON && shared_memory_type != SHMEM_TYPE_MMAP)
+- ereport(ERROR,
+- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+- errmsg("huge pages not supported with the current shared_memory_type setting")));
+-
+- /* Room for a header? */
+- Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
+-
+- if (shared_memory_type == SHMEM_TYPE_MMAP)
+- {
+- AnonymousShmem = CreateAnonymousSegment(&size);
+- AnonymousShmemSize = size;
+-
+- /* Register on-exit routine to unmap the anonymous segment */
+- on_shmem_exit(AnonymousShmemDetach, (Datum) 0);
+-
+- /* Now we need only allocate a minimal-sized SysV shmem block. */
+- sysvsize = sizeof(PGShmemHeader);
+- }
+- else
+- sysvsize = size;
+-
+- /*
+- * Loop till we find a free IPC key. Trust CreateDataDirLockFile() to
+- * ensure no more than one postmaster per data directory can enter this
+- * loop simultaneously. (CreateDataDirLockFile() does not entirely ensure
+- * that, but prefer fixing it over coping here.)
+- */
+- NextShmemSegID = statbuf.st_ino;
+-
+- for (;;)
+- {
+- IpcMemoryId shmid;
+- PGShmemHeader *oldhdr;
+- IpcMemoryState state;
+-
+- /* Try to create new segment */
+- memAddress = InternalIpcMemoryCreate(NextShmemSegID, sysvsize);
+- if (memAddress)
+- break; /* successful create and attach */
+-
+- /* Check shared memory and possibly remove and recreate */
+-
+- /*
+- * shmget() failure is typically EACCES, hence SHMSTATE_FOREIGN.
+- * ENOENT, a narrow possibility, implies SHMSTATE_ENOENT, but one can
+- * safely treat SHMSTATE_ENOENT like SHMSTATE_FOREIGN.
+- */
+- shmid = shmget(NextShmemSegID, sizeof(PGShmemHeader), 0);
+- if (shmid < 0)
+- {
+- oldhdr = NULL;
+- state = SHMSTATE_FOREIGN;
+- }
+- else
+- state = PGSharedMemoryAttach(shmid, NULL, &oldhdr);
+-
+- switch (state)
+- {
+- case SHMSTATE_ANALYSIS_FAILURE:
+- case SHMSTATE_ATTACHED:
+- ereport(FATAL,
+- (errcode(ERRCODE_LOCK_FILE_EXISTS),
+- errmsg("pre-existing shared memory block (key %lu, ID %lu) is still in use",
+- (unsigned long) NextShmemSegID,
+- (unsigned long) shmid),
+- errhint("Terminate any old server processes associated with data directory \"%s\".",
+- DataDir)));
+- break;
+- case SHMSTATE_ENOENT:
+-
+- /*
+- * To our surprise, some other process deleted since our last
+- * InternalIpcMemoryCreate(). Moments earlier, we would have
+- * seen SHMSTATE_FOREIGN. Try that same ID again.
+- */
+- elog(LOG,
+- "shared memory block (key %lu, ID %lu) deleted during startup",
+- (unsigned long) NextShmemSegID,
+- (unsigned long) shmid);
+- break;
+- case SHMSTATE_FOREIGN:
+- NextShmemSegID++;
+- break;
+- case SHMSTATE_UNATTACHED:
+-
+- /*
+- * The segment pertains to DataDir, and every process that had
+- * used it has died or detached. Zap it, if possible, and any
+- * associated dynamic shared memory segments, as well. This
+- * shouldn't fail, but if it does, assume the segment belongs
+- * to someone else after all, and try the next candidate.
+- * Otherwise, try again to create the segment. That may fail
+- * if some other process creates the same shmem key before we
+- * do, in which case we'll try the next key.
+- */
+- if (oldhdr->dsm_control != 0)
+- dsm_cleanup_using_control_segment(oldhdr->dsm_control);
+- if (shmctl(shmid, IPC_RMID, NULL) < 0)
+- NextShmemSegID++;
+- break;
+- }
+-
+- if (oldhdr && shmdt((void *) oldhdr) < 0)
+- elog(LOG, "shmdt(%p) failed: %m", oldhdr);
+- }
+-
+- /* Initialize new segment. */
+- hdr = (PGShmemHeader *) memAddress;
+- hdr->creatorPID = getpid();
+- hdr->magic = PGShmemMagic;
+- hdr->dsm_control = 0;
+-
+- /* Fill in the data directory ID info, too */
+- hdr->device = statbuf.st_dev;
+- hdr->inode = statbuf.st_ino;
+-
+- /*
+- * Initialize space allocation status for segment.
+- */
+- hdr->totalsize = size;
+- hdr->freeoffset = MAXALIGN(sizeof(PGShmemHeader));
+- *shim = hdr;
+-
+- /* Save info for possible future use */
+- UsedShmemSegAddr = memAddress;
+- UsedShmemSegID = (unsigned long) NextShmemSegID;
+-
+- /*
+- * If AnonymousShmem is NULL here, then we're not using anonymous shared
+- * memory, and should return a pointer to the System V shared memory
+- * block. Otherwise, the System V shared memory block is only a shim, and
+- * we must return a pointer to the real block.
+- */
+- if (AnonymousShmem == NULL)
+- return hdr;
+- memcpy(AnonymousShmem, hdr, sizeof(PGShmemHeader));
+- return (PGShmemHeader *) AnonymousShmem;
++ *shim = NULL;
++ return NULL;
+ }
+
+ #ifdef EXEC_BACKEND
+@@ -874,27 +441,13 @@
+ void
+ PGSharedMemoryReAttach(void)
+ {
+- IpcMemoryId shmid;
+- PGShmemHeader *hdr;
+- IpcMemoryState state;
++ PGShmemHeader *hdr = NULL;
+ void *origUsedShmemSegAddr = UsedShmemSegAddr;
+
+ Assert(UsedShmemSegAddr != NULL);
+ Assert(IsUnderPostmaster);
+
+-#ifdef __CYGWIN__
+- /* cygipc (currently) appears to not detach on exec. */
+- PGSharedMemoryDetach();
+- UsedShmemSegAddr = origUsedShmemSegAddr;
+-#endif
+-
+ elog(DEBUG3, "attaching to %p", UsedShmemSegAddr);
+- shmid = shmget(UsedShmemSegID, sizeof(PGShmemHeader), 0);
+- if (shmid < 0)
+- state = SHMSTATE_FOREIGN;
+- else
+- state = PGSharedMemoryAttach(shmid, UsedShmemSegAddr, &hdr);
+- if (state != SHMSTATE_ATTACHED)
+ elog(FATAL, "could not reattach to shared memory (key=%d, addr=%p): %m",
+ (int) UsedShmemSegID, UsedShmemSegAddr);
+ if (hdr != origUsedShmemSegAddr)
+@@ -956,12 +509,6 @@
+ {
+ if (UsedShmemSegAddr != NULL)
+ {
+- if ((shmdt(UsedShmemSegAddr) < 0)
+-#if defined(EXEC_BACKEND) && defined(__CYGWIN__)
+- /* Work-around for cygipc exec bug */
+- && shmdt(NULL) < 0
+-#endif
+- )
+ elog(LOG, "shmdt(%p) failed: %m", UsedShmemSegAddr);
+ UsedShmemSegAddr = NULL;
+ }
+--- a/src/backend/storage/ipc/dsm_impl.c
++++ b/src/backend/storage/ipc/dsm_impl.c
+@@ -234,7 +234,7 @@
+ }
+ *mapped_address = NULL;
+ *mapped_size = 0;
+- if (op == DSM_OP_DESTROY && shm_unlink(name) != 0)
++ if (op == DSM_OP_DESTROY)
+ {
+ ereport(elevel,
+ (errcode_for_dynamic_shared_memory(),
+@@ -255,9 +255,6 @@
+ */
+ ReserveExternalFD();
+
+- flags = O_RDWR | (op == DSM_OP_CREATE ? O_CREAT | O_EXCL : 0);
+- if ((fd = shm_open(name, flags, PG_FILE_MODE_OWNER)) == -1)
+- {
+ ReleaseExternalFD();
+ if (op == DSM_OP_ATTACH || errno != EEXIST)
+ ereport(elevel,
+@@ -265,79 +262,6 @@
+ errmsg("could not open shared memory segment \"%s\": %m",
+ name)));
+ return false;
+- }
+-
+- /*
+- * If we're attaching the segment, determine the current size; if we are
+- * creating the segment, set the size to the requested value.
+- */
+- if (op == DSM_OP_ATTACH)
+- {
+- struct stat st;
+-
+- if (fstat(fd, &st) != 0)
+- {
+- int save_errno;
+-
+- /* Back out what's already been done. */
+- save_errno = errno;
+- close(fd);
+- ReleaseExternalFD();
+- errno = save_errno;
+-
+- ereport(elevel,
+- (errcode_for_dynamic_shared_memory(),
+- errmsg("could not stat shared memory segment \"%s\": %m",
+- name)));
+- return false;
+- }
+- request_size = st.st_size;
+- }
+- else if (dsm_impl_posix_resize(fd, request_size) != 0)
+- {
+- int save_errno;
+-
+- /* Back out what's already been done. */
+- save_errno = errno;
+- close(fd);
+- ReleaseExternalFD();
+- shm_unlink(name);
+- errno = save_errno;
+-
+- ereport(elevel,
+- (errcode_for_dynamic_shared_memory(),
+- errmsg("could not resize shared memory segment \"%s\" to %zu bytes: %m",
+- name, request_size)));
+- return false;
+- }
+-
+- /* Map it. */
+- address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
+- MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
+- if (address == MAP_FAILED)
+- {
+- int save_errno;
+-
+- /* Back out what's already been done. */
+- save_errno = errno;
+- close(fd);
+- ReleaseExternalFD();
+- if (op == DSM_OP_CREATE)
+- shm_unlink(name);
+- errno = save_errno;
+-
+- ereport(elevel,
+- (errcode_for_dynamic_shared_memory(),
+- errmsg("could not map shared memory segment \"%s\": %m",
+- name)));
+- return false;
+- }
+- *mapped_address = address;
+- *mapped_size = request_size;
+- close(fd);
+- ReleaseExternalFD();
+-
+- return true;
+ }
+
+ /*
+@@ -506,8 +430,6 @@
+ segsize = request_size;
+ }
+
+- if ((ident = shmget(key, segsize, flags)) == -1)
+- {
+ if (op == DSM_OP_ATTACH || errno != EEXIST)
+ {
+ int save_errno = errno;
+@@ -521,16 +443,12 @@
+ return false;
+ }
+
+- *ident_cache = ident;
+- *impl_private = ident_cache;
+- }
+-
+ /* Handle teardown cases. */
+ if (op == DSM_OP_DETACH || op == DSM_OP_DESTROY)
+ {
+ pfree(ident_cache);
+ *impl_private = NULL;
+- if (*mapped_address != NULL && shmdt(*mapped_address) != 0)
++ if (*mapped_address != NULL)
+ {
+ ereport(elevel,
+ (errcode_for_dynamic_shared_memory(),
+@@ -540,7 +458,7 @@
+ }
+ *mapped_address = NULL;
+ *mapped_size = 0;
+- if (op == DSM_OP_DESTROY && shmctl(ident, IPC_RMID, NULL) < 0)
++ if (op == DSM_OP_DESTROY)
+ {
+ ereport(elevel,
+ (errcode_for_dynamic_shared_memory(),
+@@ -554,41 +472,22 @@
+ /* If we're attaching it, we must use IPC_STAT to determine the size. */
+ if (op == DSM_OP_ATTACH)
+ {
+- struct shmid_ds shm;
+-
+- if (shmctl(ident, IPC_STAT, &shm) != 0)
+- {
+ ereport(elevel,
+ (errcode_for_dynamic_shared_memory(),
+ errmsg("could not stat shared memory segment \"%s\": %m",
+ name)));
+ return false;
+ }
+- request_size = shm.shm_segsz;
+- }
+
+- /* Map it. */
+- address = shmat(ident, NULL, PG_SHMAT_FLAGS);
+- if (address == (void *) -1)
+- {
+- int save_errno;
++ int save_errno = errno;
+
+ /* Back out what's already been done. */
+- save_errno = errno;
+- if (op == DSM_OP_CREATE)
+- shmctl(ident, IPC_RMID, NULL);
+ errno = save_errno;
+-
+ ereport(elevel,
+ (errcode_for_dynamic_shared_memory(),
+ errmsg("could not map shared memory segment \"%s\": %m",
+ name)));
+ return false;
+- }
+- *mapped_address = address;
+- *mapped_size = request_size;
+-
+- return true;
+ }
+ #endif
+
+--- a/src/bin/initdb/initdb.c
++++ b/src/bin/initdb/initdb.c
+@@ -1006,38 +1006,7 @@
+ static const char *
+ choose_dsm_implementation(void)
+ {
+-#if defined(HAVE_SHM_OPEN) && !defined(__sun__)
+- int ntries = 10;
+- pg_prng_state prng_state;
+-
+- /* Initialize prng; this function is its only user in this program. */
+- pg_prng_seed(&prng_state, (uint64) (getpid() ^ time(NULL)));
+-
+- while (ntries > 0)
+- {
+- uint32 handle;
+- char name[64];
+- int fd;
+-
+- handle = pg_prng_uint32(&prng_state);
+- snprintf(name, 64, "/PostgreSQL.%u", handle);
+- if ((fd = shm_open(name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
+- {
+- close(fd);
+- shm_unlink(name);
+- return "posix";
+- }
+- if (errno != EEXIST)
+- break;
+- --ntries;
+- }
+-#endif
+-
+-#ifdef WIN32
+- return "windows";
+-#else
+ return "sysv";
+-#endif
+ }
+
+ /*
diff --git a/0004-Fix-type-casting.patch b/0004-Fix-type-casting.patch
new file mode 100644
index 000000000000..378ebfec52cd
--- /dev/null
+++ b/0004-Fix-type-casting.patch
@@ -0,0 +1,38 @@
+--- a/src/backend/utils/adt/xml.c
++++ b/src/backend/utils/adt/xml.c
+@@ -1174,7 +1174,7 @@
+ errcxt->saved_errcxt = xmlGenericErrorContext;
+ #endif
+
+- xmlSetStructuredErrorFunc((void *) errcxt, xml_errorHandler);
++ xmlSetStructuredErrorFunc((void *) errcxt, (xmlStructuredErrorFunc) xml_errorHandler);
+
+ /*
+ * Verify that xmlSetStructuredErrorFunc set the context variable we
+@@ -4781,7 +4781,7 @@
+ xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableFetchRow");
+
+ /* Propagate our own error context to libxml2 */
+- xmlSetStructuredErrorFunc((void *) xtCxt->xmlerrcxt, xml_errorHandler);
++ xmlSetStructuredErrorFunc((void *) xtCxt->xmlerrcxt, (xmlStructuredErrorFunc) xml_errorHandler);
+
+ if (xtCxt->xpathobj == NULL)
+ {
+@@ -4835,7 +4835,7 @@
+ xtCxt->xpathobj->nodesetval != NULL);
+
+ /* Propagate our own error context to libxml2 */
+- xmlSetStructuredErrorFunc((void *) xtCxt->xmlerrcxt, xml_errorHandler);
++ xmlSetStructuredErrorFunc((void *) xtCxt->xmlerrcxt, (xmlStructuredErrorFunc) xml_errorHandler);
+
+ *isnull = false;
+
+@@ -4978,7 +4978,7 @@
+ xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableDestroyOpaque");
+
+ /* Propagate our own error context to libxml2 */
+- xmlSetStructuredErrorFunc((void *) xtCxt->xmlerrcxt, xml_errorHandler);
++ xmlSetStructuredErrorFunc((void *) xtCxt->xmlerrcxt, (xmlStructuredErrorFunc) xml_errorHandler);
+
+ if (xtCxt->xpathscomp != NULL)
+ {
diff --git a/0005-Added-missing-headers.patch b/0005-Added-missing-headers.patch
new file mode 100644
index 000000000000..cae20c6ae13b
--- /dev/null
+++ b/0005-Added-missing-headers.patch
@@ -0,0 +1,10 @@
+--- a/src/interfaces/ecpg/compatlib/informix.c
++++ b/src/interfaces/ecpg/compatlib/informix.c
+@@ -15,6 +15,7 @@
+ #include "pgtypes_numeric.h"
+ #include "sqlca.h"
+ #include "sqltypes.h"
++#include "../include/sqltypes.h"
+
+ /* this is also defined in ecpglib/misc.c, by defining it twice we don't have to export the symbol */
+
diff --git a/0006-Fix-duplicate-case.patch b/0006-Fix-duplicate-case.patch
new file mode 100644
index 000000000000..90f6f3060d33
--- /dev/null
+++ b/0006-Fix-duplicate-case.patch
@@ -0,0 +1,33 @@
+--- a/src/include/access/tupmacs.h
++++ b/src/include/access/tupmacs.h
+@@ -61,11 +61,11 @@
+ return Int16GetDatum(*((const int16 *) T));
+ case sizeof(int32):
+ return Int32GetDatum(*((const int32 *) T));
++ default:
+ #if SIZEOF_DATUM == 8
+- case sizeof(Datum):
++ if (attlen == sizeof(Datum))
+ return *((const Datum *) T);
+ #endif
+- default:
+ elog(ERROR, "unsupported byval length: %d", attlen);
+ return 0;
+ }
+@@ -193,12 +193,13 @@
+ case sizeof(int32):
+ *(int32 *) T = DatumGetInt32(newdatum);
+ break;
++ default:
+ #if SIZEOF_DATUM == 8
+- case sizeof(Datum):
++ if (attlen == sizeof(Datum)) {
+ *(Datum *) T = newdatum;
+- break;
++ return;
++ }
+ #endif
+- default:
+ elog(ERROR, "unsupported byval length: %d", attlen);
+ }
+ }
diff --git a/0007-Unversioned-libs.patch b/0007-Unversioned-libs.patch
new file mode 100644
index 000000000000..610551b1a601
--- /dev/null
+++ b/0007-Unversioned-libs.patch
@@ -0,0 +1,10 @@
+--- a/configure
++++ b/configure
+@@ -539,6 +539,7 @@
+ else
+ as_ln_s='cp -pR'
+ fi
++as_ln_s='cp -pR'
+ rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+ rmdir conf$$.dir 2>/dev/null
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..279af49807b3
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,110 @@
+# Maintainer: Gonzalo Exequiel Pedone <hipersayan DOT x AT gmail DOT com>
+# Contributor: Levente Polyak <anthraxx[at]archlinux[dot]org>
+# Contributor: Dan McGee <dan@archlinux.org>
+
+_android_arch=x86-64
+
+pkgname=android-${_android_arch}-postgresql
+pkgver=16.1
+pkgrel=1
+arch=('any')
+pkgdesc="Sophisticated object-relational DBMS (Android, ${_android_arch})"
+url='https://www.postgresql.org/'
+license=('custom:PostgreSQL')
+depends=("android-${_android_arch}-icu"
+ "android-${_android_arch}-openldap"
+ "android-${_android_arch}-libxml2"
+ "android-${_android_arch}-libxslt"
+ "android-${_android_arch}-lz4"
+ "android-${_android_arch}-openssl"
+ "android-${_android_arch}-readline"
+ "android-${_android_arch}-zlib"
+ "android-${_android_arch}-zstd")
+makedepends=('android-configure'
+ 'util-linux'
+ "android-${_android_arch}-tcl"
+ "tcl")
+optdepends=("android-${_android_arch}-tcl: for PL/Tcl support")
+options=(!strip !buildflags staticlibs !emptydirs)
+source=("https://ftp.postgresql.org/pub/source/v${pkgver}/postgresql-${pkgver}.tar.bz2"
+ '0001-Force-utf8-codeset.patch'
+ '0002-Disable-unsupported-functions.patch'
+ '0003-Disable-shm.patch'
+ '0004-Fix-type-casting.patch'
+ '0005-Added-missing-headers.patch'
+ '0006-Fix-duplicate-case.patch'
+ '0007-Unversioned-libs.patch')
+md5sums=('9cbfb9076ed06384471802b850698a6d'
+ '4c19ab4024b4079e668117d79a9058b3'
+ '75dad9c605ab1987c22e5b0da564dccb'
+ '3305f78f93bed96409971e5ca269314d'
+ 'f88a4fb16aef45bbd6f01a912cd7a8fa'
+ 'f52a2e35dbb0bf71f4cc553ebd008c10'
+ 'd1e8c384acb46460750c1af057449578'
+ '7bc0f291f718c4fc3181addf7c8d0b14')
+
+prepare() {
+ cd "${srcdir}/postgresql-${pkgver}"
+ source android-env ${_android_arch}
+
+ if [ "${ANDROID_MINIMUM_PLATFORM}" -lt 26 ]; then
+ patch -p1 -i ../0001-Force-utf8-codeset.patch
+ patch -p1 -i ../0003-Disable-shm.patch
+ fi
+
+ patch -p1 -i ../0002-Disable-unsupported-functions.patch
+ patch -p1 -i ../0004-Fix-type-casting.patch
+ patch -p1 -i ../0005-Added-missing-headers.patch
+ patch -p1 -i ../0006-Fix-duplicate-case.patch
+ patch -p1 -i ../0007-Unversioned-libs.patch
+
+ sed -i 's|PTHREAD_LIBS="-lpthread"|PTHREAD_LIBS=""|g' configure
+ sed -i 's|storage/lwlocknames.h|storage/lmgr/lwlocknames.h|g' src/include/storage/lwlock.h
+
+ if [ "${ANDROID_MINIMUM_PLATFORM}" -lt 24 ]; then
+ sed -i 's|fseeko|fseek|g' src/backend/utils/adt/genfile.c
+ sed -i 's|fseeko|fseek|g' src/bin/pg_dump/pg_backup_archiver.c
+ sed -i 's|ftello|ftell|g' src/bin/pg_dump/pg_backup_archiver.c
+ sed -i 's|fseeko|fseek|g' src/bin/pg_dump/pg_backup_custom.c
+ sed -i 's|ftello|ftell|g' src/bin/pg_dump/pg_backup_custom.c
+ sed -i 's|fseeko|fseek|g' src/bin/pg_dump/pg_backup_tar.c
+ sed -i 's|ftello|ftell|g' src/bin/pg_dump/pg_backup_tar.c
+ fi
+}
+
+build() {
+ cd "${srcdir}/postgresql-${pkgver}"
+ source android-env ${_android_arch}
+
+ export CFLAGS="${CFLAGS} -I${PWD}/src/backend"
+ export CXXFLAGS="${CXXFLAGS} -I${PWD}/src/backend"
+ export TCL_CONFIG_SH="${ANDROID_PREFIX_LIB}/tclConfig.sh"
+
+ android-${_android_arch}-configure \
+ --sysconfdir="${ANDROID_PREFIX_ETC}" \
+ --with-libxml \
+ --with-openssl \
+ --with-tcl \
+ --with-readline \
+ --with-icu \
+ --with-ldap \
+ --with-libxslt \
+ --with-lz4 \
+ --with-zstd \
+ --enable-nls \
+ --enable-thread-safety \
+ --disable-rpath
+ make $MAKEFLAGS
+}
+
+package() {
+ cd "${srcdir}/postgresql-${pkgver}"
+ source android-env ${_android_arch}
+
+ make DESTDIR="$pkgdir" install
+ rm -rf "${pkgdir}/${ANDROID_PREFIX_BIN}"
+ ${ANDROID_STRIP} -g --strip-unneeded "${pkgdir}"/${ANDROID_PREFIX_LIB}/*.so
+ ${ANDROID_STRIP} -g "$pkgdir"/${ANDROID_PREFIX_LIB}/*.a
+ rm -f "${pkgdir}"/${ANDROID_PREFIX_LIB}/*.so.*
+ rm -rf "${pkgdir}/usr"
+}