When is it possible to localize a scheme along a closed subscheme? If we have $Z\subset X$ a closed irreducible subscheme of an integral scheme $X$ (which you can take to have various further niceness properties if you want), one can take its generic point $\eta_Z$ and localize at it, to get a local ring with quotient field the quotient field of $Z$.
However, intuitively, I'd like to be able to "take a small neighborhood of $Z$" and not just of $\eta_Z$, i.e. I'd like a canonically constructed subscheme of $X$ whose "special fiber" is $Z$ and doesn't contain any points of $X$ besides the ones which specialize to points of $Z$. Certainly in general, I wouldn't expect this to be possible, so I don't expect a general functorial construction like usual localizations. But are there known cases when something like this exists?
I'm particularly interested in when $\pi:X\to S$ is a flat family or something similarly nice, and $Z$ is a section of $\pi$, so that what I'm asking for is basically like the "relative local ring of the point $Z$ over the base $S$". Then I'd also like to ask that the pullback of my "localization at $Z$" to any fiber of $\pi$ over a closed point of $S$ yields the localization of that fiber at the point where it intersects $Z$.
In this case, if $X$ is a trivial bundle over $S$, like if $X=S\times_k Y$ for some $Y$, then obviously this is possible; I'm wondering if it's possible more generally.
(I'd also appreciate an explicit counterexample to it being possible in general flat families, since I don't expect it to be possible in that generality, but find it difficult to prove it's impossible in any particular case.)
 A: Let $W \subset X$ denote the set of points specializing to $Z$ with the induced topology. Denote $\mathcal{O}_W$ the pullback of $\mathcal{O}_X$. Then $W = (W, \mathcal{O}_W)$ is a locally ringed space and we can ask:
Question: is $W$ a scheme?
Usually not: for example if $X = \mathbf{P}^2_k$ and $Z$ is a line, then this is false. (Hint: show that there aren't any nonempty affine opens.)
Sometimes yes: if $Z = \{x\}$ consists of a closed point, then $W$ is the spectrum of the local ring $\mathcal{O}_{X, x}$.
Here is a criterion: suppose that we can write $W = \bigcap_{i \in I} U_i$ as the intersection of quasi-compact opens with the following properties: (a) $\forall i, j \in I, \exists k \in I$ such that $U_k \subset U_i \cap U_j$ and (b) $\forall i, j \in I$ if $U_i \subset U_j$ then $U_i \to U_j$ is an affine morphism. Then $W = \lim U_i$ is a scheme.
If $X$ is a smooth projective surface then (a) and (b) hold if $Z$ is the fibre of a nonconstant morphism from $X$ to a curve or if $Z$ can be blown down (to a point on another algebraic surface -- does not work if the contraction gives an algebraic space).
If $X$ is a smooth projective surface over the algebraic closure of a finite field and $f : X \to S$ is a nonconstant morphism to a smooth projective curve and $Z$ is the image of a section of $f$, then it is often the case that the normal bundle of $Z$ in $X$ is negative (think about elliptic surfaces for example). Then by Artin you can contract $Z$ and hence $W$ is a scheme.
Anyway, it is fun to play around with these ideas, but I do not know a good way to work with $W$ like this. Many people would, I think, instead consider the formal completion of $X$ along $Z$ and work with that instead.
