Porting PostgreSQL To The Win32 Platform

offbeatlossData Management

Nov 22, 2012 (4 years and 6 months ago)

255 views

Porting PostgreSQL To The Win32 Platform
BRUCE MOMJIAN
January,2012
This presentation outlines the challenges of porting PostgreSQL
from Unix to the Win32 platform.
Creative Commons Attribution License http://momjian.us/presentations
Porting PostgreSQL To The Win32 Platform 1/22
Pre-8.0
Porting PostgreSQL To The Win32 Platform 2/22
Problems With Cygwin

Installation requirements

Installation bloat,security concerns

Fifty-connection limit

Performance
Porting PostgreSQL To The Win32 Platform 3/22
Constraints

Do not break the Unix build

Do no make the code harder to understand

Limit code duplication for the new port

Minimize the amount of new code for the port
Soution —Teamwork
Porting PostgreSQL To The Win32 Platform 4/22
Commercial Ports

PeerDirect

SRA

Connix
Porting PostgreSQL To The Win32 Platform 5/22
Target Operating System

Windows NT,2000/2003,XP

NTFS
Porting PostgreSQL To The Win32 Platform 6/22
Toolkit - MinGW

libraries map Unix calls to Win32 calls (MinGW)

provides Unix build environment (Msys)
Porting PostgreSQL To The Win32 Platform 7/22
Major Issue - Fork vs.CreateProcess

passing variables inherited via fork

attaching to shared memory that is usually inherited
Porting PostgreSQL To The Win32 Platform 8/22
Typical New Unix Process
fork() exec()
datadata
stack stack stack
text
data
texttext
Porting PostgreSQL To The Win32 Platform 9/22
New PostgreSQL Process on Unix
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
fork()
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
text
data
stack
data
text
stack
Porting PostgreSQL To The Win32 Platform 10/22
New PostgreSQL Process on Win32
exec()
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
Shared
Memory
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
￿￿￿￿￿￿￿￿￿￿￿
text
data
stack
data
stack
text
Porting PostgreSQL To The Win32 Platform 11/22
File System

’/’ vs ’\’

root directory,/vs.C:\

carriage return/line feed

COPY

open()

character checks

.EXE extension

symlinks vs junction points

file system sync() vs per-file commit()
Porting PostgreSQL To The Win32 Platform 12/22
File SystemAtomicity,Concurrency

rename() and unlink() fixed using open() flags

FILE_SHARE_READ

FILE_SHARE_WRITE

FILE_SHARE_DELETE
Porting PostgreSQL To The Win32 Platform 13/22
Command Line

system()

’&’ vs START/B

cp/copy,rm/del

copydir as service

single vs double quotes
Porting PostgreSQL To The Win32 Platform 14/22
Environment Variables

$HOME directory

$SHELL vs $COMSPEC

$EDITOR defaults
Porting PostgreSQL To The Win32 Platform 15/22
Shell Scripts Convert to C Programs

initdb

pg_ctl

create*,drop*,vacuumdb,pg_dumpall
Porting PostgreSQL To The Win32 Platform 16/22
Interprocess Communication

signals,thread listening on named pipe

cancel key handling

popen() when run from a service
Porting PostgreSQL To The Win32 Platform 17/22
/port Centralization
copydir.c getrusage.c pgsleep.c srandom.c
crypt.c gettimeofday.c pgstrcasecmp.c strdup.c
dirmod.c inet_aton.c pipe.c strerror.c
exec.c isinf.c qsort.c strtol.c
fseeko.c kill.c rand.c strtoul.c
getaddrinfo.c memcmp.c random.c thread.c
gethostname.c noblock.c rint.c unsetenv.c
getopt.c open.c snprintf.c
getopt_long.c path.c sprompt.c
Porting PostgreSQL To The Win32 Platform 18/22
Build Environment

adjust Makefiles and build

errno vs.GetLastError()
Porting PostgreSQL To The Win32 Platform 19/22
Kernel

IPC - memory,semaphores

sleep interrupted

getrusage()

memory allocation from shared libraries
Porting PostgreSQL To The Win32 Platform 20/22
Miscellaneous

user name lookups,no/etc/passwd

locale vs code page

no accessable timezone database

relocatable installs

Win32 service

installer MSI
Porting PostgreSQL To The Win32 Platform 21/22
Conclusion
http://momjian.us/presentations
Porting PostgreSQL To The Win32 Platform 22/22