If youyour polygon is raster, digitize it.
Once youyour polygon is really a polygon :), a first solution lies, like @WhiteboxDev said, it's the straight skeleton, but it has the problem that, besides the centerline you want, it also returnreturns a lot of segments radiating from that line to the border of your polygon. But if you have PostGIS 2.2+, you can use ST_ApproximateMedialAxis()
instead, which is what you want.